IEEE754

Status: in-progress Progress: 0%
#math #computer

Floating Number

In computer, correct math statement frequently becomes incorrect due to floating point error.

For example, let $$ \begin{aligned} a &= \sqrt{2}\ b &= a * a\ c &= b-2\ \end{aligned} $$

then, $c$ is expected to be 0. However, in Python, we have

import math
a = math.sqrt(2)
b = a * a
c = b - 2
print(c)  # Output: 4.440892098500626e-16

which is not 0. This is because $a$ cannot be represented exactly in floating point format.

📚 Back to Learning