Draft:0.30000000000000004

  • Comment: This is an essay or blog post rather than an encyclopedic essay. This is a particular example of the subject covered in Floating-point arithmetic. KylieTastic (talk) 10:51, 8 November 2024 (UTC)



0.30000000000000004 is the result in the most common example used on the internet to demonstrate small deviations between human common decimal fractions math and computer common binary floating point arithmetic.

Problem and example

edit

The example is that 0.2 + 0.1 results in 0.30000000000000004 in binary floating-point with the most common datatype IEEE 754[1] 'double' (binary64).

These deviations evolve because the binary datatypes can't exactly represent most of decimal fractions but use approximated binary deputies.

Thus, the calculation becomes 0.2000000000000000111022... + 0.1000000000000000055511... , the binary exact result 0.3000000000000000166533... isn't representable in the datatype, would require 54 bit of significand where only 53 are available, and thus becomes rounded to a representable value, 0.3000000000000000444089... for which the 'SRT' ( Shortest Round Tripping ) decimal correspondent is 0.30000000000000004 .

For verification one can use the IEEE 754 Calculator from Prof. Weitz, HAW Hamburg, it can be found at weitz.de/ieee

Reproduction of problem

edit

In e.g. spreadsheets it needs some efforts to demonstrate these deviations, they cover up by e.g. only displaying 15 significant digits.

A funny while not exact in every detail video about it can be found on youtube 'Why do computers suck at math?'.

The problem / example has got it's own website: 'Floating Point Math' ( 0.30000000000000004.com ).

More Info about this type of deviation and background can be found at Goldberg: 'What Every Computer Scientist Should Know About Floating-Point Arithmetic' [1], or on a less scientific level at: 'What Every Programmer Should Know About Floating-Point Arithmetic' [2].

The problem

edit

It is not! the only example, but one of myriads of similar deviations, it's not only additions but all types of calculations affected, and not all problem cases involve rounding, e.g. 4.4 + 2.2 -> 6.6000000000000005 fails without.

The deviations are often considered neglectable as being very very very small, that's right but they may stack up, multiply up, or even 'exponentionally explode' and then harm usability of computer calculated results.

References

edit
  1. ^ 754-2019 - IEEE Standard for Floating-Point Arithmetic ( caution: paywall ). 2019. doi:10.1109/IEEESTD.2019.8766229. ISBN 978-1-5044-5924-2. Retrieved 2024-10-29.