Floating point roundoff on Windows

15 views
Skip to first unread message

lswa...@limebv.nl

unread,
Sep 5, 2016, 8:14:26 AM9/5/16
to PyInstaller
Dear all,

If I run the following code as 
python main.py

main.py:
import numpy as np

a = 0.999999999999999888977697537484
print("%.30f" % a)
print("%.30f" % np.sqrt(a))

The output is:
0.999999999999999888977697537484
0.999999999999999888977697537484

However, after feeding it through pyinstaller (Windows 7, 32 bit) and running the executable, the output is
0.999999999999999888977697537484
1.000000000000000000000000000000


On Ubuntu 64-bit, the python output and executable output are both
0.999999999999999888977697537484
0.999999999999999888977697537484

Doesn't seem to matter whether I use numpy or 'import math' 

Does anyone have any idea about this?

Kind regards,
Lense

Hartmut Goebel

unread,
Sep 5, 2016, 9:36:57 AM9/5/16
to pyins...@googlegroups.com
Am 02.09.2016 um 12:23 schrieb lswa...@limebv.nl:
Does anyone have any idea about this?

I can't see how is this related to PyInstaller. Please ask the numpy guys.

--
Schönen Gruß
Hartmut Goebel
Dipl.-Informatiker (univ), CISSP, CSSLP, ISO 27001 Lead Implementer
Information Security Management, Security Governance, Secure Software Development

Goebel Consult, Landshut
http://www.goebel-consult.de

Blog: http://www.goebel-consult.de/blog/ehrlichkeit-made-in-germany
Kolumne: http://www.cissp-gefluester.de/2012-01-in-die-cloud-in-die-cloud-aber-wo-soll-die-sein

lswa...@limebv.nl

unread,
Sep 6, 2016, 8:15:26 AM9/6/16
to PyInstaller
If you read the whole post, you will see that the bug is also present when importing math instead of numpy.
So
main.py:
import math

a = 0.999999999999999888977697537484
print("%.30f" % a)
print("%.30f" % math.sqrt(a))

gives the exact same outputs.
In that respect, it has everything to do with PyInstaller. And nothing with NumPy.



Op maandag 5 september 2016 15:36:57 UTC+2 schreef Hartmut Goebel:

bwoodsend

unread,
Apr 14, 2020, 3:08:50 AM4/14/20
to PyInstaller
I image it's due to your window's system being 32-bit but not sure entirely why it differs in PyInstaller.

What do you get if you run the following normally and from PyInstaller?

import sys
print(sys.float_info())


And if you replace `a = .999999...` in your code with
import sys
a
= 1 - sys.float_info().epsilon





Reply all
Reply to author
Forward
0 new messages