floating-point
Installation
SKILL.md
Floating point
What a float is
An IEEE 754 double is sign x mantissa x 2^exponent with a 53-bit mantissa. It represents numbers of that form exactly and nothing else.
0.1, 0.2, and 0.3 are not of that form:
>>> from decimal import Decimal
>>> Decimal(0.1)
Decimal('0.1000000000000000055511151231257827021181583404541015625')
>>> 0.1 + 0.2 == 0.3
False
Not a language quirk. Binary cannot represent one tenth, just as decimal cannot represent one third.
Two consequences: