Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!

Bug 619896

Summary: dev-lang/python pow() functionality too imprecise on N32 MIPS, leading to test failures elsewhere
Product: Gentoo Linux Reporter: Mart Raudsepp <leio>
Component: Current packagesAssignee: Python Gentoo Team <python>
Status: RESOLVED WORKSFORME    
Severity: normal CC: mips
Priority: Normal    
Version: unspecified   
Hardware: MIPS   
OS: Linux   
Whiteboard:
Package list:
Runtime testing required: ---

Description Mart Raudsepp gentoo-dev 2017-05-27 21:40:26 UTC
On MIPS:

# python3.5 -c 'print(10.0**20)'
1.0000000000000036e+20


While a simple C testcase works fine:

#include <math.h>
#include <stdio.h>

int main() {
	double src = 10.0;
	double p = 20;
	printf("%lf\n", pow(src, p));
}

BUT only if at least -O1 or -Os is applied (with -O0 or no -O option it gives a similar 36 containing value).

Given that libm pow() works correctly with -Os, -O1, -O2 and event -Ofast, I don't understand how python is getting it wrong.


Additionally this can be observed with python2.7:

Python 2.7.13 (default, Apr 19 2017, 12:32:15) 
[GCC 5.4.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 10.0**20
1.0000000000000036e+20
>>> print(10.0**20)
1e+20


while for python3.5 and python3.6 it gives 1.0000000000000036e+20 for both cases.

This all causes dev-python/Babel tests to fail from
https://github.com/python-babel/babel/blob/master/tests/test_numbers.py#L34
with python3 (interestingly they seem to pass with python2.7, perhaps due to the above mentioned mystery somehow).
Comment 1 Mart Raudsepp gentoo-dev 2017-05-27 21:43:03 UTC
everything behaves the same when using pow(10.0, 20) in place of 10.0**20, including the 2.7 oddity
Comment 2 Mike Gilbert gentoo-dev 2017-12-16 20:43:21 UTC
Someone with MIPS hardware will need to fix this. As far as I know, the problem does not occur on other archs.
Comment 3 Matt Turner gentoo-dev 2018-03-28 01:19:02 UTC
# python3.5 -c 'print(10.0**20)'
1e+20

And Babel's tests pass for me on both my Yeeloong and my Loongson3A.