-
-
Notifications
You must be signed in to change notification settings - Fork 30.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
testFsum failure caused by constant folding of a float expression #83173
Comments
Title: testFsum failure caused by constant folding of a float expression Description: AssertionError: -4.309103330548428e+214 != -1.0 This occurs when testing '([1.7**(i+1)-1.7**i for i in range(1000)] + [-1.7**1000], -1.0)' in test_values. Next the test_math.py file is touched on the android device to force recompilation of the module and testFsum becomes surprisingly successful. Investigation:
on x86_64:
>>> 1.7**10
201.59939004489993
>>> (1.7**10).hex()
'0x1.9332e34080c95p+7'
on arm64:
>>> 1.7**10
201.59939004489996
>>> (1.7**10).hex()
'0x1.9332e34080c96p+7' The output of the following foo.py module that has been run on x86_64 and arm64 are attached to this issue: #######################
import math, dis
def test_fsum():
x = [1.7**(i+1)-1.7**i for i in range(10)] + [-1.7**10]
return x
y = test_fsum()
print(y)
print(math.fsum(y))
dis.dis(test_fsum)
####################### The only difference between both dissasembly of test_fsum() is at bytecode 16 that loads the folded constant 1.7**10. Conclusion: This is confirmed by changing testFsum to prevent constant folding by replacing 1000 in the testFsum expression with a variable whose value is 1000. In that case the test_math module compiled on x86_64 is successful on arm64. This could be a fix for this issue unless this fix would be hiding another problem such as .pyc files portability across different platforms and my knowledge of IEEE 754 is too superficial to answer that point. |
So if I'm understanding correctly, the cause of the issue is that the value I think it should be easy to rewrite the test so that it precomputes the powers of |
Note that the exact values of |
Yes PR #61715 does fix the problem. |
Fixed in master and 3.8. Not sure this is worth backporting to 3.7. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: