Title: PowerPC exponentiation and round() interaction
Type: behavior Stage:
Components: Library (Lib) Versions: Python 2.7
Status: closed Resolution: works for me
Dependencies: Superseder:
Assigned To: Nosy List: mark.dickinson, serhiy.storchaka, squeakbat
Priority: normal Keywords:

Created on 2013-04-29 03:29 by squeakbat, last changed 2013-04-29 08:36 by mark.dickinson. This issue is now closed.

File name Uploaded Description Edit squeakbat, 2013-04-29 03:29
Messages (7)
msg188033 - (view) Author: Ellen Wang (squeakbat) Date: 2013-04-29 03:29
This is only on a PowerPC, specifically a p2020, running Debian 7.0 wheezy, python 2.7.3.

Calling round() seems to corrupt something (in the floating point state?) that causes subsequent exponentiation (the ** operator) to be wrong:

Python 2.7.3 (default, Jan  2 2013, 16:38:11)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 2 ** -2
>>> round(1)
>>> 2 ** -2

Cool.  Huh?
msg188034 - (view) Author: Ellen Wang (squeakbat) Date: 2013-04-29 03:57
Here's an example that uses only math library functions and float literals, presumably with a simpler code path:

Python 2.7.3 (default, Jan  2 2013, 16:38:11)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import math
>>> math.exp(-2.0)
>>> math.ceil(1.0)
>>> math.exp(-2.0)

By the way, the equivalent C program (using exp() and ceil()) on the same platform behaves correctly, so it's not an obvious libc or fpu problem.
msg188039 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2013-04-29 07:13
I can't reproduce this on 2.7.4. Could you please test 2.7.4?
msg188040 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2013-04-29 07:21
Hmm:  it's not an obvious Python bug, either:  both math.exp and math.ceil are simple wrappers around the libm functions, so there's little room for things to go wrong between Python and the OS.

Are you in a position to compile Python from source on your platform?

What was the equivalent C program you tried?  What's the compiler on this platform?  Note that gcc (I believe) evaluates math function calls for constants at compile time (using MPFR), rather than run time, which would mean if your C program simply does "exp(-2.0);" then it's not even using the OS libm.
msg188042 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2013-04-29 07:23
Oh, sorry, I missed PowerPC. Please ignore my previous comment.
msg188044 - (view) Author: Ellen Wang (squeakbat) Date: 2013-04-29 07:26
OK.  My bad.  I should have been tipped off that the program didn't need -lm to link.  Output from C code:


Feel free to close.  I'll have to look into this on my own.  Thanks and sorry.
msg188048 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2013-04-29 08:36
No problem; thanks for the update.  By the way, if you do file an OS bug report of some form, it would be great if you could add a link to this issue.  That might help anyone who encounters this in Python in the future.

Date User Action Args
2013-04-29 08:36:45mark.dickinsonsetstatus: open -> closed
resolution: works for me
messages: + msg188048
2013-04-29 07:26:34squeakbatsetmessages: + msg188044
2013-04-29 07:23:23serhiy.storchakasetmessages: + msg188042
2013-04-29 07:21:10mark.dickinsonsetmessages: + msg188040
2013-04-29 07:13:31mark.dickinsonsetnosy: + mark.dickinson
2013-04-29 07:13:04serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg188039
2013-04-29 03:57:10squeakbatsetmessages: + msg188034
2013-04-29 03:29:26squeakbatcreate