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

Ben Bacarisse ben.usenet at bsb.me.uk
Sat Nov 20 17:44:28 EST 2021


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.

-- 
Ben.


More information about the Python-list mailing list