Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>I would have expected e1+e2 to equal e3+e4. </p> </blockquote> <p>That's not entirely unlike expecting </p> <pre><code> floor( 5/3 ) + floor( 2/3 + 1 ) </code></pre> <p>to equal</p> <pre><code> floor( 5/3 + 2/3 ) + floor( 1 ) </code></pre> <p>except you're multiplying by 2^53 before taking the floor.</p> <p>Using 12 bit precision floating point and truncation with your values:</p> <pre> 1.0 = 1.00000000000 1.1 = 1.00011001100 1.2 = 1.00110011001 1.0 + 1.1 = 10.00011001100 // extended during sum r1 = 1.0 + 1.1 = 10.0001100110 // truncated to 12 bit r1 + 1.2 = 11.01001100101 // extended during sum r2 = r1 + 1.2 = 11.0100110010 // truncated to 12 bit 1.1 + 1.2 = 10.01001100110 // extended during sum r3 = 1.1 + 1.2 = 10.0100110011 // truncated to 12 bit r3 + 1.0 = 11.01001100110 // extended during sum r4 = r3 + 1.0 = 11.0100110011 // truncated to 12 bit </pre> <p>So changing the order of operations/truncations causes the the error to change, and r4 != r2. If you add 1.1 and 1.2 in this system, the last bit carries, so in not lost on truncation. If you add 1.0 to 1.1, the last bit of 1.1 is lost and so the result is not the same.</p> <p>In one ordering, the rounding (by truncation) removes a trailing <code>1</code>. </p> <p>In the other ordering, the rounding removes a trailing <code>0</code> both times.</p> <p>One does not equal zero; so the errors are not the same.</p> <p>Doubles have many more bits of precision, and C# probably uses rounding rather than truncation, but hopefully this simple model shows you different errors can happen with different orderings of the same values.</p> <p>The difference between fp and maths is that + is shorthand for 'add then round' rather than just add.</p>
    singulars
    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.
    3. 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