How floating errors are handled by a computer

I understand that floating-point numbers have limitations so this can be expected:

>>> 0.1 + 0.2 == 0.3
False

But why is this so? Can computers not store 0.45, 0.55 reliably or correctly?

>>> 0.45 + 0.55 == 1.00
True

I want to know how in the first case the computer was unable to correct its inaccuracy, but in a later version.

+4
source share
1 answer

As you know, most decimal numbers cannot be stored exactly. This is true for all of your above numbers except 1.0.

. 0.3 . , .

0.1 + 0.2, , 0.3. "" .

, 0.1 0.2 . , , - 0.30000000000000004.

0.45 + 0.55 .

+4

Source: https://habr.com/ru/post/1681010/


All Articles