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

Chris Angelico rosuav at gmail.com
Fri Nov 19 16:21:18 EST 2021


On Sat, Nov 20, 2021 at 7:39 AM dn via Python-list
<python-list at python.org> wrote:
> >>  >>> 0.3 + 0.3 + 0.3 == 0.9
> >> False
> >
> > That's because 0.3 is not 3/10. It's not because floats are
> > "unreliable" or "inaccurate". It's because the ones you're entering
> > are not what you think they are.
> >
> > When will people understand this?
> > (Probably never. Sigh.)
>
>
> Am not aware of any institution which teaches the inner-workings of a
> CPU/ALU/FPU/GPU in a general programming class, ie "Programming" and
> particularly "Coding", have diverged from "Computer Science" - in at
> least this respect.
>

I think what I find annoying about this sort of thing is that people
triumphantly announce that the computer is WRONG. It's the numeric
equivalent of XKCD 169, and people get smug for the exact same reason,
and perhaps unfortunately, do not get their arms cut off.

"Computer, give me a number as close as possible to three tenths."

"HAH! THAT ISN'T THREE TENTHS! Hah you suck!"

*slash*

ChrisA


More information about the Python-list mailing list