Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6678607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:15:47+00:00 2026-05-26T04:15:47+00:00

This little piece of code is making me crazy: #include <stdio.h> int main() {

  • 0

This little piece of code is making me crazy:

#include <stdio.h>

    int main() 
{
double x;
const double d=0.1;
x=d ;
for (int i=0; i<30; i++) 
    {
    printf("Cycle %d  Value :%.20e \n",i,x);
    x=x*(double)11.-(double)10*d; //11*0.1 = 1.1 - 10*0.1 = 1 => 0.1

    }       
return 0;
}

In fact I was trying to demonstrate a pathological case due to the internal representation
of floating numbers in IEEE 754 standard.
On a MacOs or windows machine the final output line will read:

Cycle 29 Value :1.28084153156127500000e+13

But on a Linux ( Scientific Linux 5.4 ) the code will run with no problem.
Reading I have found that:

On BSD systems such as FreeBSD, NetBSD and OpenBSD, the hardware double-precision rounding mode is the default, giving the greatest compatibility with native double precision platforms. On x86 GNU/Linux systems the default mode is extended precision (with the aim of providing increased accuracy).

On the same page GCC INTRO was explained how to enable double precision rounding on a Linux system but not how to use extended precision on other systems.
Is that possible on MacOs or Windows ? and how ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T04:15:48+00:00Added an answer on May 26, 2026 at 4:15 am

    Simply using extended precision on OS X is easy:

    x=11.L*x - 10.L*d;
    

    The L suffix causes the two literals to be long doubles instead of doubles, which forces the entire expression to be evaluated in 80-bit extended per C’s expression evaluation rules.

    That aside, there seems to be some confusion in your question; you say “… on a Linux the code will run with no problem.” A couple points:

    • Both the OS X result and the Linux result conform to IEEE-754 and to the C standard. There is no “problem” with either one of them.
    • The OS X result is reproducible on hardware that does not support the (non-standard) 80-bit floating point type. The Linux result is not.
    • Computations that depend on intermediate results being kept in 80-bit extended are fragile; changing compiler options, optimization settings, or even program flow may cause the result to change. The OS X result will be stable across such changes.

    Ultimately, you must keep in mind that floating-point arithmetic is not real arithmetic. The fact that the result obtained on Linux is closer to the result obtained when evaluating the expression with real numbers does not make that approach better (or worse).

    For every case where automatic usage of extended precision saved a naive user of floating-point, I can show you a case where the unpredictability of that evaluation mode introduces a subtle and hard-to-diagnose bug. These are commonly called “excess-precision” bugs; one of the most famous recent examples was a bug that allowed users to put 2.2250738585072011e-308 into a web form and crash the server. The ultimate cause is precisely that the compiler going behind the programmer’s back and maintaining more precision than it was instructed to. OS X was not affected by this bug because double-precision expressions are evaluated in double-precision, not extended.

    People can be educated about the gotchas of floating-point arithmetic, so long as the system is both reproducible and portable. Evaluating double-precision expressions in double and single-precision in single provides those attributes. Using extended-precision evaluation undermines them. You cannot do serious engineering in an environment where your tools are unpredictable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this little piece of code : private Dictionary<string, IList<KeyValuePair<int, string>>> EnumsCollection =
I'm trying to get this piece of code working a little better. I suspect
I have this little piece of code that just checks for a particular text
Let's say I have this little piece of code: <?php $tmp = str_split('hello world!',2);
So, i'm having a lot of trouble with this little piece of code. An
I've got this nifty little piece of code here that self-propogates ad infinitum every
In this little piece of code, what is the fourth line all about? from
So I have this little piece of code: System.out.println(Size: + mounts.keySet().size()); for (JHttpPath entry
I was writing this little piece of code as an exercise in object-oriented programming.
Possible Duplicate: Which keycode for escape key with jQuery This little piece of code

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.