[pypy-svn] pypy post-release-1.5: In-progress.
arigo
commits-noreply at bitbucket.org
Mon Apr 25 11:14:15 CEST 2011
Author: Armin Rigo <arigo at tunes.org>
Branch: post-release-1.5
Changeset: r43555:1fdb135e7cb0
Date: 2011-04-25 10:50 +0200
http://bitbucket.org/pypy/pypy/changeset/1fdb135e7cb0/
Log: In-progress.
diff --git a/pypy/translator/c/node.py b/pypy/translator/c/node.py
--- a/pypy/translator/c/node.py
+++ b/pypy/translator/c/node.py
@@ -11,7 +11,7 @@
from pypy.translator.c.support import c_char_array_constant, barebonearray
from pypy.translator.c.primitive import PrimitiveType, name_signed
from pypy.rlib import exports
-from pypy.rlib.rfloat import isinf, isnan
+from pypy.rlib.rfloat import isfinite
from pypy.rlib.rstackovf import _StackOverflow
from pypy.translator.c import extfunc
from pypy.translator.tool.cbuild import ExternalCompilationInfo
@@ -793,7 +793,7 @@
node = db.getcontainernode(value._obj)
expr = 'NULL /*%s*/' % node.name
node.where_to_copy_me.append('&%s' % access_expr)
- elif typeOf(value) == Float and (isinf(value) or isnan(value)):
+ elif typeOf(value) == Float and not isfinite(value):
db.late_initializations.append(('%s' % access_expr, db.get(value)))
expr = '0.0 /* patched later by %sinfinity */' % (
'-+'[value > 0])
diff --git a/pypy/translator/c/test/test_genc.py b/pypy/translator/c/test/test_genc.py
--- a/pypy/translator/c/test/test_genc.py
+++ b/pypy/translator/c/test/test_genc.py
@@ -273,7 +273,7 @@
assert res == 1.5
def test_nan_and_special_values():
- from pypy.rlib.rfloat import isnan, isinf, copysign
+ from pypy.rlib.rfloat import isnan, isinf, isfinite, copysign
inf = 1e300 * 1e300
assert isinf(inf)
nan = inf/inf
@@ -283,6 +283,7 @@
(inf, lambda x: isinf(x) and x > 0.0),
(-inf, lambda x: isinf(x) and x < 0.0),
(nan, isnan),
+ (42.0, isfinite),
(0.0, lambda x: not x and copysign(1., x) == 1.),
(-0.0, lambda x: not x and copysign(1., x) == -1.),
]:
diff --git a/pypy/rlib/rbigint.py b/pypy/rlib/rbigint.py
--- a/pypy/rlib/rbigint.py
+++ b/pypy/rlib/rbigint.py
@@ -1,7 +1,7 @@
from pypy.rlib.rarithmetic import LONG_BIT, intmask, r_uint, r_ulonglong
from pypy.rlib.rarithmetic import ovfcheck, r_longlong, widen
from pypy.rlib.rarithmetic import most_neg_value_of_same_type
-from pypy.rlib.rfloat import isinf, isnan
+from pypy.rlib.rfloat import isfinite
from pypy.rlib.debug import make_sure_not_resized, check_regular_int
from pypy.rlib.objectmodel import we_are_translated, specialize
from pypy.rlib import jit
@@ -173,9 +173,15 @@
def fromfloat(dval):
""" Create a new bigint object from a float """
# This function is not marked as pure because it can raise
+ if isfinite(dval):
+ return rbigint._fromfloat_finite(dval)
+ else:
+ raise OverflowError
+
+ @staticmethod
+ @jit.purefunction
+ def _fromfloat_finite(dval):
sign = 1
- if isinf(dval) or isnan(dval):
- raise OverflowError
if dval < 0.0:
sign = -1
dval = -dval
diff --git a/pypy/rlib/objectmodel.py b/pypy/rlib/objectmodel.py
--- a/pypy/rlib/objectmodel.py
+++ b/pypy/rlib/objectmodel.py
@@ -267,14 +267,15 @@
In RPython, floats cannot be used with ints in dicts, anyway.
"""
from pypy.rlib.rarithmetic import intmask
- from pypy.rlib.rfloat import isinf, isnan
- if isinf(f):
- if f < 0.0:
- return -271828
- else:
- return 314159
- elif isnan(f):
- return 0
+ from pypy.rlib.rfloat import isfinite, isinf
+ if not isfinite(f):
+ if isinf(f):
+ if f < 0.0:
+ return -271828
+ else:
+ return 314159
+ else: #isnan(f):
+ return 0
v, expo = math.frexp(f)
v *= TAKE_NEXT
hipart = int(v)
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,7 +10,7 @@
from pypy.objspace.std.longobject import W_LongObject
from pypy.rlib.rarithmetic import ovfcheck_float_to_int, intmask, LONG_BIT
from pypy.rlib.rfloat import (
- isinf, isnan, INFINITY, NAN, copysign, formatd,
+ isinf, isnan, isfinite, INFINITY, NAN, copysign, formatd,
DTSF_ADD_DOT_0, DTSF_STR_PRECISION)
from pypy.rlib.rbigint import rbigint
from pypy.rlib.objectmodel import we_are_translated
@@ -102,7 +102,7 @@
def float_hex__Float(space, w_float):
value = w_float.floatval
- if isinf(value) or isnan(value):
+ if not isfinite(value):
return str__Float(space, w_float)
if value == 0.0:
if copysign(1., value) == -1.:
@@ -136,15 +136,15 @@
def float2string(space, w_float, code, precision):
x = w_float.floatval
# we special-case explicitly inf and nan here
- if isinf(x):
+ if isfinite(x):
+ s = formatd(x, code, precision, DTSF_ADD_DOT_0)
+ elif isinf(x):
if x > 0.0:
s = "inf"
else:
s = "-inf"
- elif isnan(x):
+ else: # isnan(x):
s = "nan"
- else:
- s = formatd(x, code, precision, DTSF_ADD_DOT_0)
return space.wrap(s)
def repr__Float(space, w_float):
@@ -179,7 +179,7 @@
if opname == 'eq' or opname == 'ne':
def do_compare_bigint(f1, b2):
"""f1 is a float. b2 is a bigint."""
- if isinf(f1) or isnan(f1) or math.floor(f1) != f1:
+ if not isfinite(f1) or math.floor(f1) != f1:
return opname == 'ne'
b1 = rbigint.fromfloat(f1)
res = b1.eq(b2)
@@ -189,7 +189,7 @@
else:
def do_compare_bigint(f1, b2):
"""f1 is a float. b2 is a bigint."""
- if isinf(f1) or isnan(f1):
+ if not isfinite(f1):
return op(f1, 0.0)
if opname == 'gt' or opname == 'le':
# 'float > long' <==> 'ceil(float) > long'
@@ -457,8 +457,6 @@
if x == 0.0:
if y < 0.0:
- if isinf(y):
- return space.wrap(INFINITY)
raise OperationError(space.w_ZeroDivisionError,
space.wrap("0.0 cannot be raised to "
"a negative power"))
diff --git a/pypy/rlib/rstruct/ieee.py b/pypy/rlib/rstruct/ieee.py
--- a/pypy/rlib/rstruct/ieee.py
+++ b/pypy/rlib/rstruct/ieee.py
@@ -87,12 +87,13 @@
raise ValueError("invalid size value")
sign = rfloat.copysign(1.0, x) < 0.0
- if rfloat.isinf(x):
- mant = r_ulonglong(0)
- exp = MAX_EXP - MIN_EXP + 2
- elif rfloat.isnan(x):
- mant = r_ulonglong(1) << (MANT_DIG-2) # other values possible
- exp = MAX_EXP - MIN_EXP + 2
+ if not rfloat.isfinite(x):
+ if rfloat.isinf(x):
+ mant = r_ulonglong(0)
+ exp = MAX_EXP - MIN_EXP + 2
+ else: # rfloat.isnan(x):
+ mant = r_ulonglong(1) << (MANT_DIG-2) # other values possible
+ exp = MAX_EXP - MIN_EXP + 2
elif x == 0.0:
mant = r_ulonglong(0)
exp = 0
More information about the Pypy-commit
mailing list