- #36
wle
- 336
- 157
Couple of things:
1) While Python (or rather 64-bit IEEE floats) can represent neither the numbers 25.15 nor 25.149999999999977 perfectly precisely, it can represent them both closely enough to distinguish them:
The closest floating-point approximations of these numbers are not the same.
2) Whatever that
Checking the documentation seems to confirm this:
1) While Python (or rather 64-bit IEEE floats) can represent neither the numbers 25.15 nor 25.149999999999977 perfectly precisely, it can represent them both closely enough to distinguish them:
Python:
>>> x = 25.15
>>> y = 25.149999999999977
>>> x == y
False
>>> x - y
2.1316282072803006e-14
2) Whatever that
:n
format directive is doing, it is clearly not trying to represent floating-point numbers to anywhere near machine precision:
Python:
>>> '{:n}'.format(1.23456789)
'1.23457'
and, just above:
'n'
Number. This is the same as 'g'
, except that it uses the current locale setting to insert the appropriate number separator characters.
'g'
[...] With no precision given, uses a precision of 6
significant digits for float. [...]