classification
Title: float('nan')**2 != nan. float('nan')**2 error 33 on windows
Type: behavior Stage: patch review
Components: Interpreter Core Versions: Python 3.2, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: mark.dickinson Nosy List: ezio.melotti, mark.dickinson, mdonolo, tim.peters
Priority: normal Keywords: patch

Created on 2009-12-17 18:42 by mdonolo, last changed 2009-12-30 16:24 by mark.dickinson. This issue is now closed.

Files
File name Uploaded Description Edit
unnamed mdonolo, 2009-12-17 19:35
unnamed mdonolo, 2009-12-18 19:07
floatobject.c mdonolo, 2009-12-18 21:58
float_pow_testcases.patch mark.dickinson, 2009-12-19 15:20 Testcases for float_pow
float_pow_testcases2.patch mark.dickinson, 2009-12-19 17:37 Corrected and expanded testcases.
float_pow.patch mark.dickinson, 2009-12-19 20:48
Messages (14)
msg96523 - (view) Author: Marcos Donolo (mdonolo) Date: 2009-12-17 18:42
I am not getting the expected result for the ** operator on windows,
python 2.6
I do...
a=float('nan')
b=a*a
then b is nan which is right but if I do 
b = a**2 I get.
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: (33, 'Domain error')

If I do a**2 on ubuntu, python 2.6 I get nan again.
msg96526 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2009-12-17 19:22
Yep.  There's not much consistency in inf/nan handling across platforms, 
though the situation is slowly getting better.  math.pow makes an effort 
to handle these special cases correctly (for some value of correctly), and 
it would probably make some sense to have the builtin pow behave the same 
way.

Would you be interested in contributing a fix?
msg96529 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2009-12-17 19:33
Closed 7536 as a duplicate of this issue.
msg96530 - (view) Author: Marcos Donolo (mdonolo) Date: 2009-12-17 19:35
I will give it a shot.

On Thu, Dec 17, 2009 at 11:22 AM, Mark Dickinson <report@bugs.python.org>wrote:

>
> Mark Dickinson <dickinsm@gmail.com> added the comment:
>
> Yep.  There's not much consistency in inf/nan handling across platforms,
> though the situation is slowly getting better.  math.pow makes an effort
> to handle these special cases correctly (for some value of correctly), and
> it would probably make some sense to have the builtin pow behave the same
> way.
>
> Would you be interested in contributing a fix?
>
> ----------
> stage:  -> needs patch
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <http://bugs.python.org/issue7534>
> _______________________________________
>
msg96531 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2009-12-17 19:39
Great!  For math.pow, see the function math_pow in Modules/mathmodule.c;  
some sort of (careful!) cut-and-paste job from there to float_pow in 
Objects/floatobject.c might do the trick.
msg96574 - (view) Author: Marcos Donolo (mdonolo) Date: 2009-12-18 19:07
Ok, I have patch ready. how do we go about putting it in?
thanks.
marcos

On Thu, Dec 17, 2009 at 11:52 AM, Ezio Melotti <report@bugs.python.org>wrote:

>
> Changes by Ezio Melotti <ezio.melotti@gmail.com>:
>
>
> ----------
> nosy: +ezio.melotti
> versions: +Python 3.1
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <http://bugs.python.org/issue7534>
> _______________________________________
>
msg96576 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2009-12-18 19:09
Just upload it here clicking on 'Browse' next to the 'File' field and
then click on 'Submit Changes'.
msg96586 - (view) Author: Marcos Donolo (mdonolo) Date: 2009-12-18 21:59
I had to handle nans and infs in different places.
msg96605 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2009-12-19 14:20
Thanks for this;  I'll take a look.

Looks like we need some tests for this, too.
msg96606 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2009-12-19 15:20
Here's a set of testcases (patch against trunk) for float pow, based on 
Annex F of the C99 specification.
msg96620 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2009-12-19 17:37
There were two incorrect tests in float_pow_testcases.patch:

+            self.assertEqualAndEqualSign(pow_op(-INF, -0.5), -0.0)
+            self.assertEqualAndEqualSign(pow_op(-INF, -2.0), -0.0)

these should both have had 0.0 in place of -0.0.  Here are corrected and 
slightly expanded tests;  I've also fixed an incorrect doctest (0**nan 
should be nan, not 0) in Lib/test/ieee754.txt.
msg96646 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2009-12-19 20:48
Okay;  I had to rework Marcos' patch a bit to get all the tests to pass.  
Here's the result.

I propose making these changes only in 2.7 and 3.2, not in 2.6 or 3.1;  
it's just possible that there's code out there that relies on some of 
the current behaviour;  I don't want to risk breaking that code in a 
bugfix release.  Does this seem reasonable?

It's possible I should be putting the tests in test_pow rather than 
test_float.
msg97028 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2009-12-30 12:13
Fixed in trunk in r77139.  I'll wait to check that the buildbots are 
happy, and then merge to py3k.
msg97037 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2009-12-30 16:24
Merged to py3k in r77146.
History
Date User Action Args
2009-12-30 16:24:17mark.dickinsonsetstatus: open -> closed
resolution: fixed
messages: + msg97037
2009-12-30 12:13:14mark.dickinsonsetmessages: + msg97028
2009-12-21 16:47:52mark.dickinsonsetstage: needs patch -> patch review
2009-12-19 20:48:50mark.dickinsonsetfiles: + float_pow.patch

messages: + msg96646
versions: + Python 2.7, Python 3.2, - Python 2.6, Python 3.1
2009-12-19 17:37:40mark.dickinsonsetfiles: + float_pow_testcases2.patch

messages: + msg96620
2009-12-19 15:20:13mark.dickinsonsetfiles: + float_pow_testcases.patch
keywords: + patch
messages: + msg96606
2009-12-19 14:20:32mark.dickinsonsetmessages: + msg96605
2009-12-19 14:11:12mark.dickinsonsetassignee: mark.dickinson
2009-12-18 21:59:15mdonolosetmessages: + msg96586
2009-12-18 21:58:08mdonolosetfiles: + floatobject.c
2009-12-18 19:09:33ezio.melottisetmessages: + msg96576
2009-12-18 19:07:21mdonolosetfiles: + unnamed

messages: + msg96574
2009-12-17 19:52:38ezio.melottisetnosy: + ezio.melotti

versions: + Python 3.1
2009-12-17 19:39:30mark.dickinsonsetmessages: + msg96531
2009-12-17 19:35:19mdonolosetfiles: + unnamed

messages: + msg96530
title: float('nan')**2 != nan. float('inf')**2 != inf. float('nan')**2 error 33 on windows -> float('nan')**2 != nan. float('nan')**2 error 33 on windows
2009-12-17 19:33:28mark.dickinsonsetmessages: + msg96529
title: float('nan')**2 != nan. float('nan')**2 error 33 on windows -> float('nan')**2 != nan. float('inf')**2 != inf. float('nan')**2 error 33 on windows
2009-12-17 19:32:33mark.dickinsonlinkissue7536 superseder
2009-12-17 19:22:02mark.dickinsonsetmessages: + msg96526
stage: needs patch
2009-12-17 18:44:27ezio.melottisetpriority: normal
nosy: + mark.dickinson
2009-12-17 18:42:55mdonolocreate