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

Chris Angelico rosuav at gmail.com
Sat Nov 20 18:57:55 EST 2021


On Sun, Nov 21, 2021 at 10:55 AM Ben Bacarisse <ben.usenet at bsb.me.uk> wrote:
>
> Grant Edwards <grant.b.edwards at gmail.com> writes:
>
> > On 2021-11-20, Ben Bacarisse <ben.usenet at bsb.me.uk> wrote:
> >
> >> You seem to be agreeing with me.  It's the floating point part that is
> >> the issue, not the base itself.
> >
> > No, it's the base. Floating point can't represent 3/10 _because_ it's
> > base 2 floating point. Floating point in base 10 doesn't have any
> > problem representing 3/10.
>
> Every base has the same problem for some numbers.  It's the floating
> point part that causes the problem.
>
> Binary and decimal stand out because we write a lot of decimals in
> source code and computers use binary, but if decimal floating point were
> common (as it increasingly is) different fractions would become the oft
> quoted "surprise" results.
>

And if decimal floating point were common, other "surprise" behaviour
would be cited, like how x < y and (x+y)/2 < x.

ChrisA


More information about the Python-list mailing list