Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Simply <em>using</em> extended precision on OS X is easy:</p> <pre><code>x=11.L*x - 10.L*d; </code></pre> <p>The <code>L</code> suffix causes the two literals to be <code>long double</code>s instead of <code>double</code>s, which forces the entire expression to be evaluated in 80-bit extended per C's expression evaluation rules.</p> <p>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:</p> <ul> <li>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.</li> <li>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.</li> <li>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.</li> </ul> <p>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).</p> <p>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 <code>2.2250738585072011e-308</code> into a web form and <em>crash the server</em>. 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.</p> <p>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.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload