[pypy-svn] r77347 - in pypy/branch/fast-forward/pypy/rlib: rstruct test
afa at codespeak.net
afa at codespeak.net
Fri Sep 24 17:02:15 CEST 2010
Author: afa
Date: Fri Sep 24 17:02:12 2010
New Revision: 77347
Modified:
pypy/branch/fast-forward/pypy/rlib/rstruct/ieee.py
pypy/branch/fast-forward/pypy/rlib/test/test_rstruct.py
Log:
float('nan') is not RPython, use prebuilt constants instead.
This should fix applevel tests with -A:
rarithmetic.pyc contains NAN and INFINITY
which could not be unmarshalled.
Modified: pypy/branch/fast-forward/pypy/rlib/rstruct/ieee.py
==============================================================================
--- pypy/branch/fast-forward/pypy/rlib/rstruct/ieee.py (original)
+++ pypy/branch/fast-forward/pypy/rlib/rstruct/ieee.py Fri Sep 24 17:02:12 2010
@@ -58,7 +58,7 @@
if exp == MAX_EXP - MIN_EXP + 2:
# nan or infinity
- result = float('nan') if mant else float('inf')
+ result = rarithmetic.NAN if mant else rarithmetic.INFINITY
elif exp == 0:
# subnormal or zero
result = math.ldexp(mant, MIN_EXP - MANT_DIG)
Modified: pypy/branch/fast-forward/pypy/rlib/test/test_rstruct.py
==============================================================================
--- pypy/branch/fast-forward/pypy/rlib/test/test_rstruct.py (original)
+++ pypy/branch/fast-forward/pypy/rlib/test/test_rstruct.py Fri Sep 24 17:02:12 2010
@@ -2,7 +2,7 @@
from pypy.rpython.test.tool import BaseRtypingTest, LLRtypeMixin, OORtypeMixin
from pypy.rlib.rstruct.runpack import runpack
from pypy.rlib.rstruct import ieee
-from pypy.rlib.rarithmetic import LONG_BIT
+from pypy.rlib.rarithmetic import LONG_BIT, INFINITY, NAN, isnan
from pypy.translator.c.test.test_genc import compile
import struct
@@ -48,10 +48,18 @@
return ieee.unpack_float(s, False)
c_unpack = compile(unpack, [str])
- s = c_pack(123.456)
- assert s == pack(123.456)
- assert c_unpack(s) == 123.456
-
- s = c_pack(-123.456)
- assert s == pack(-123.456)
- assert c_unpack(s) == -123.456
+ def check_roundtrip(x):
+ s = c_pack(x)
+ assert s == pack(x)
+ if not isnan(x):
+ assert unpack(s) == x
+ assert c_unpack(s) == x
+ else:
+ assert isnan(unpack(s))
+ assert isnan(c_unpack(s))
+
+ check_roundtrip(123.456)
+ check_roundtrip(-123.456)
+ check_roundtrip(INFINITY)
+ check_roundtrip(NAN)
+
More information about the Pypy-commit
mailing list