Bug in floating point multiplication

Michael Poeltl michael.poeltl at univie.ac.at
Thu Jul 2 11:10:50 EDT 2015


hi Steven,

I'm running python-3.4.2 on a linuxmint16 box and CANNOT reproduce
it is just that
int(i*x) == i
is never True!

hope that helps
regards
Michael

* Steven D'Aprano <steve at pearwood.info> [2015-07-02 16:56]:
> Despite the title, this is not one of the usual "Why can't Python do
> maths?" "bug" reports.
> 
> Can anyone reproduce this behaviour? If so, please reply with the version of
> Python and your operating system. Printing sys.version will probably do.
> 
> 
> x = 1 - 1/2**53
> assert x == 0.9999999999999999
> for i in range(1, 1000000):
>     if int(i*x) == i:
>         print(i); break
> 
> 
> Using Jython and IronPython, the loop runs to completion. That is the
> correct behaviour, or so I am lead to believe. Using Python 2.6, 2.7 and
> 3.3 on Centos and Debian, it prints 2049 and breaks. That should not
> happen. If you can reproduce that (for any value of i, not necessarily
> 2049), please reply.
> 
> See also http://bugs.python.org/issue24546 for more details.
> 
> 
> 
> -- 
> Steven
> 
> -- 
> https://mail.python.org/mailman/listinfo/python-list

-- 
  Michael Poeltl <michael.poeltl at univie.ac.at>
  Computational Materials Physics at University
  Wien, Sensengasse 8/12, A-1090 Wien, AUSTRIA
  http://cmp.univie.ac.at/
  http://homepage.univie.ac.at/michael.poeltl/
  using elinks-0.12, mutt-1.5.21, and vim-7.3,
  with python-3.4.2, on linux mint 16 (petra)   :-)
  fon: +43-1-4277-51409

  "Lehrend lernen wir!"



More information about the Python-list mailing list