[pypy-svn] r76148 - in pypy/branch/fast-forward/pypy: objspace/std rlib
benjamin at codespeak.net
benjamin at codespeak.net
Mon Jul 12 16:10:41 CEST 2010
Author: benjamin
Date: Mon Jul 12 16:10:38 2010
New Revision: 76148
Modified:
pypy/branch/fast-forward/pypy/objspace/std/floatobject.py
pypy/branch/fast-forward/pypy/rlib/rarithmetic.py
Log:
use ovfcheck_float_to_int in trunc__Float
Modified: pypy/branch/fast-forward/pypy/objspace/std/floatobject.py
==============================================================================
--- pypy/branch/fast-forward/pypy/objspace/std/floatobject.py (original)
+++ pypy/branch/fast-forward/pypy/objspace/std/floatobject.py Mon Jul 12 16:10:38 2010
@@ -9,8 +9,7 @@
from pypy.objspace.std.noneobject import W_NoneObject
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 (formatd, LONG_BIT, FL_MAXINT, FL_MININT,
- INFINITY)
+from pypy.rlib.rarithmetic import formatd, LONG_BIT, INFINITY
from pypy.rlib.rbigint import rbigint
from pypy.rlib.objectmodel import we_are_translated
from pypy.rlib import rfloat
@@ -79,8 +78,12 @@
space.wrap("cannot convert float infinity to long"))
def trunc__Float(space, w_floatobj):
whole = math.modf(w_floatobj.floatval)[1]
- if FL_MININT < whole < FL_MAXINT:
- return space.newint(int(whole))
+ try:
+ i = ovfcheck_float_to_int(whole)
+ except OverflowError:
+ pass
+ else:
+ return space.wrap(i)
try:
return W_LongObject.fromfloat(w_floatobj.floatval)
except OverflowError:
Modified: pypy/branch/fast-forward/pypy/rlib/rarithmetic.py
==============================================================================
--- pypy/branch/fast-forward/pypy/rlib/rarithmetic.py (original)
+++ pypy/branch/fast-forward/pypy/rlib/rarithmetic.py Mon Jul 12 16:10:38 2010
@@ -50,9 +50,6 @@
LONG_MASK = _Ltest*2-1
LONG_TEST = _Ltest
-FL_MAXINT = float(LONG_TEST - 1)
-FL_MININT = float(-LONG_TEST)
-
INFINITY = 1e200 * 1e200
NAN = INFINITY / INFINITY
More information about the Pypy-commit
mailing list