[pypy-svn] pypy default: Negative values can be raised to the nan power.
alex_gaynor
commits-noreply at bitbucket.org
Tue Feb 1 16:00:55 CET 2011
Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch:
Changeset: r41526:57363f9b7479
Date: 2011-02-01 09:59 -0500
http://bitbucket.org/pypy/pypy/changeset/57363f9b7479/
Log: Negative values can be raised to the nan power.
diff --git a/pypy/objspace/std/floatobject.py b/pypy/objspace/std/floatobject.py
--- a/pypy/objspace/std/floatobject.py
+++ b/pypy/objspace/std/floatobject.py
@@ -10,12 +10,13 @@
from pypy.objspace.std.longobject import W_LongObject
from pypy.rlib.rarithmetic import ovfcheck_float_to_int, intmask, isinf, isnan
from pypy.rlib.rarithmetic import (LONG_BIT, INFINITY, copysign,
- formatd, DTSF_ADD_DOT_0, DTSF_STR_PRECISION)
+ formatd, DTSF_ADD_DOT_0, DTSF_STR_PRECISION, NAN)
from pypy.rlib.rbigint import rbigint
from pypy.rlib.objectmodel import we_are_translated
from pypy.rlib import rfloat
from pypy.tool.sourcetools import func_with_new_name
+
import math
from pypy.objspace.std.intobject import W_IntObject
@@ -340,7 +341,7 @@
x = w_float1.floatval
y = w_float2.floatval
if y == 0.0:
- raise FailedToImplementArgs(space.w_ZeroDivisionError, space.wrap("float division"))
+ raise FailedToImplementArgs(space.w_ZeroDivisionError, space.wrap("float division"))
return W_FloatObject(x / y)
truediv__Float_Float = div__Float_Float
@@ -424,6 +425,8 @@
# unlike "math.pow(-1.0, bignum)". See http://mail.python.org/
# - pipermail/python-bugs-list/2003-March/016795.html
if x < 0.0:
+ if math.isnan(y):
+ return W_FloatObject(NAN)
if math.floor(y) != y:
raise OperationError(space.w_ValueError,
space.wrap("negative number cannot be "
diff --git a/pypy/objspace/std/test/test_floatobject.py b/pypy/objspace/std/test/test_floatobject.py
--- a/pypy/objspace/std/test/test_floatobject.py
+++ b/pypy/objspace/std/test/test_floatobject.py
@@ -170,21 +170,23 @@
def test_special_float_method(self):
class a(object):
- def __float__(self):
- self.ar = True
+ def __float__(self):
+ self.ar = True
return None
inst = a()
- raises(TypeError, float, inst)
- assert inst.ar
+ raises(TypeError, float, inst)
+ assert inst.ar
- class b(object):
- pass
- raises((AttributeError, TypeError), float, b())
+ class b(object):
+ pass
+ raises((AttributeError, TypeError), float, b())
def test_getnewargs(self):
assert 0.0 .__getnewargs__() == (0.0,)
def test_pow(self):
+ import math
+
def pw(x, y):
return x ** y
def espeq(x, y):
@@ -200,6 +202,8 @@
assert pw(-1.0, 1e200) == 1.0
if self.py26:
assert pw(0.0, float("-inf")) == float("inf")
+ assert math.isnan(pw(-3, float("nan")))
+ assert math.isnan(pw(-3., float("nan")))
def test_pow_neg_base(self):
import math
More information about the Pypy-commit
mailing list