Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Firstly, consider that there are many numbers which are rational in base 10, but not in a binary floating point representation. For example, the floating point value of 26.82 is actually <code>26.8200000000000002842170943040400743484497</code></p> <p>Naturally, if you keep adding this to itself some errors creep in, but up to 15 significant digits you should be fine - add this 1000 times and the sum is actually <code>26819.9999999997671693563461303710937500000000</code></p> <p>The interesting question though is when we multiple 26.82 by 1000.0 we get <code>26820.0000000000000000000000000000000000000000</code> - how does it do that?</p> <p>The answer there is simply that 26820.0 <em>does</em> have an exact binary representation, and the multiplication operation is smart enough to spot that - even multiplying by 1001.0 and subtracting 26.82 would still get you an exact answer.</p> <p>Here's a few interesting links </p> <ul> <li><a href="http://www.h-schmidt.net/FloatConverter/" rel="nofollow">http://www.h-schmidt.net/FloatConverter/</a> - this lets you look at single-precision representation of floating point numbers, and can be useful in really understanding floats</li> <li>This <a href="https://wiki.php.net/rfc/rounding" rel="nofollow">RFC on PHP rounding</a> is tangentially interesting as it covers some of the issues around rounding floats</li> <li>and <a href="http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html" rel="nofollow">What Every Computer Scientist Should Know About Floating-Point Arithmetic</a> </li> </ul>
    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.
    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