Unexpected behaviour of math.floor, round and int functions (rounding)

Peter J. Holzer hjp-python at hjp.at
Sun Nov 21 13:59:20 EST 2021


On 2021-11-21 10:57:55 +1100, Chris Angelico wrote:
> And if decimal floating point were common, other "surprise" behaviour
> would be cited, like how x < y and (x+y)/2 < x.

Yup. Took me a bit to find an example, but this can happen. My HP-48
calculator uses a mantissa of 12 decimal digits.

666666666666 + 666666666667 = 1333333333330
1333333333330 / 2 = 666666666665

666666666665 < 666666666666. QED.

        hp


-- 
   _  | Peter J. Holzer    | Story must make more sense than reality.
|_|_) |                    |
| |   | hjp at hjp.at         |    -- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |       challenge!"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://mail.python.org/pipermail/python-list/attachments/20211121/4444e31b/attachment.sig>


More information about the Python-list mailing list