Mark Dickinson added the comment:

Actually, there are two potential sources of confusion here:
1. Python uses the round-ties-to-even rounding mode, which means cases that are 
*exactly* halfway between two target values round to the value with even last 
digit. This rule is being used in your first example (4.625), which is a value 
that's exactly representable in the IEEE 754 binary64 format that Python 
typically uses to represent floats, and is exactly halfway between 4.2 and 4.3.

2. It might look as though round-ties-to-even applies in the second and third 
cases, too, but that's not the case, since these values *aren't* exactly 
halfway between the relevant decimal values, thanks to the representation error 
incurred when translating to the binary64 format. The value specified by the 
literal "4.645" is stored internally as 
"4.644999999999999573674358543939888477325439453125", which is a tiny amount 
closer to 4.64 than to 4.65, so it rounds to 4.64. The value 4.655 works 
similarly.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue30453>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to