On Sat, Nov 20, 2021 at 5:08 AM ast <ast@invalid> wrote:
>
> Le 19/11/2021 à 03:51, MRAB a écrit :
> > On 2021-11-19 02:40, 2qdxy4rzwzuui...@potatochowder.com wrote:
> >> On 2021-11-18 at 23:16:32 -0300,
> >> René Silva Valdés <rene.silva.val...@gmail.com> wrote:
> >>
> >>> Hello, I would like to report the following issue:
> >>>
> >>> Working with floats i noticed that:
> >>>
> >>> int(23.99999999999999/12) returns 1, and
> >>> int(23.999999999999999/12) returns 2
> >>>
> >>> This implies that int() function is rounding ...
> >>
> >> It's not int() that's doing the rounding; that second numerator is being
> >> rounded before being divided by 12:
> >>
> >>      Python 3.9.7 (default, Oct 10 2021, 15:13:22)
> >>      [GCC 11.1.0] on linux
> >>      Type "help", "copyright", "credits" or "license" for more
> >> information.
> >>      >>> 23.999999999999999
> >>      24.0
> >>      >>> (23.999999999999999).hex()
> >>      '0x1.8000000000000p+4'
> >>
> > I think this is a bit clearer because it shows that it's not just being
> > rounded for display:
> >
> > Python 3.10.0 (tags/v3.10.0:b494f59, Oct  4 2021, 19:00:18) [MSC v.1929
> > 64 bit (AMD64)] on win32
> > Type "help", "copyright", "credits" or "license" for more information.
> >  >>> 23.99999999999999 == 24
> > False
> >  >>> 23.999999999999999 == 24
> > True
>
>  >>> 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.)

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to