[pypy-svn] r47001 - in pypy/dist/pypy/module/struct: . test
arigo at codespeak.net
arigo at codespeak.net
Fri Sep 28 12:25:47 CEST 2007
Author: arigo
Date: Fri Sep 28 12:25:47 2007
New Revision: 47001
Modified:
pypy/dist/pypy/module/struct/ieee.py
pypy/dist/pypy/module/struct/test/test_ieee.py
Log:
Test ieee after translation too. Bug fix.
Modified: pypy/dist/pypy/module/struct/ieee.py
==============================================================================
--- pypy/dist/pypy/module/struct/ieee.py (original)
+++ pypy/dist/pypy/module/struct/ieee.py Fri Sep 28 12:25:47 2007
@@ -87,10 +87,12 @@
bias = 1023
exp = 11
prec = 52
+ mantissa_scale_factor = 0.5 ** prec # this is constant-folded if it's
+ # right after the 'if'
mantissa = r_longlong(bytes[size-2] & ((1<<(15-exp))-1))
for i in range(size-3, -1, -1):
mantissa = mantissa << 8 | bytes[i]
- mantissa = 1 + float(mantissa) / (1<<prec)
+ mantissa = 1 + mantissa * mantissa_scale_factor
mantissa *= 0.5
e = (bytes[-1] & 0x7f) << (exp - 7)
e += (bytes[size-2] >> (15 - exp)) & ((1<<(exp - 7)) -1)
Modified: pypy/dist/pypy/module/struct/test/test_ieee.py
==============================================================================
--- pypy/dist/pypy/module/struct/test/test_ieee.py (original)
+++ pypy/dist/pypy/module/struct/test/test_ieee.py Fri Sep 28 12:25:47 2007
@@ -15,16 +15,26 @@
def test_pack():
for number, size, bigendian, expected in testcases:
+ print 'test_pack:', number, size, bigendian
res = []
pack_float(res, number, size, bigendian)
- assert res == list(expected)
+ assert ''.join(res) == expected
def test_unpack():
for expected, size, bigendian, input in testcases:
+ print 'test_unpack:', expected, size, bigendian
assert len(input) == size
res = unpack_float(input, bigendian)
if size == 8:
assert res == expected # exact result expected
else:
assert abs(res - expected) < 1E-6
+
+
+def test_llinterpreted():
+ from pypy.rpython.test.test_llinterp import interpret
+ def f():
+ test_pack()
+ test_unpack()
+ interpret(f, [])
More information about the Pypy-commit
mailing list