Author: mattip <[email protected]>
Branch: missing-ndarray-attributes
Changeset: r60252:54e9819b3e75
Date: 2013-01-20 22:44 +0200
http://bitbucket.org/pypy/pypy/changeset/54e9819b3e75/
Log: implement byteswap for longfloat
diff --git a/pypy/module/micronumpy/types.py b/pypy/module/micronumpy/types.py
--- a/pypy/module/micronumpy/types.py
+++ b/pypy/module/micronumpy/types.py
@@ -14,7 +14,7 @@
from pypy.rpython.lltypesystem import lltype, rffi
from pypy.rlib.rstruct.runpack import runpack
from pypy.rlib.rstruct.nativefmttable import native_is_bigendian
-from pypy.rlib.rstruct.ieee import (float_pack, float_unpack,
+from pypy.rlib.rstruct.ieee import (float_pack, float_unpack, pack_float,
unpack_float, unpack_float128)
from pypy.tool.sourcetools import func_with_new_name
from pypy.rlib import jit
@@ -1539,6 +1539,12 @@
fval = unpack_float128(s, native_is_bigendian)
return self.box(fval)
+ def byteswap(self, w_v):
+ value = self.unbox(w_v)
+ result = StringBuilder(12)
+ pack_float(result, value, 12, not native_is_bigendian)
+ return self.box(unpack_float128(result.build(),
native_is_bigendian))
+
class NonNativeFloat96(Float96):
pass
@@ -1566,6 +1572,12 @@
fval = unpack_float128(s, native_is_bigendian)
return self.box(fval)
+ def byteswap(self, w_v):
+ value = self.unbox(w_v)
+ result = StringBuilder(16)
+ pack_float(result, value, 16, not native_is_bigendian)
+ return self.box(unpack_float128(result.build(),
native_is_bigendian))
+
class NonNativeFloat128(Float128):
pass
diff --git a/pypy/rlib/rarithmetic.py b/pypy/rlib/rarithmetic.py
--- a/pypy/rlib/rarithmetic.py
+++ b/pypy/rlib/rarithmetic.py
@@ -624,7 +624,7 @@
T = rffi.LONGLONG
arg = float2longlong(arg)
elif T == lltype.LongFloat:
- raise NotImplemented('cannot byteswap LongFloat')
+ assert False
else:
# we cannot do arithmetics on small ints
arg = widen(arg)
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
@@ -184,14 +184,14 @@
sign = r_ulonglong(sign)
return ((sign << BITS - 1) | (exp << MANT_DIG - 1)) | mant
-def float_pack80(x):
- """Convert a Python float x into two 64-bit unsigned integers
+def float_pack80(_x):
+ """Convert a Python float or longfloat x into two 64-bit unsigned integers
with 80 bit extended representation."""
MIN_EXP = -16381
MAX_EXP = 16384
MANT_DIG = 64
BITS = 80
-
+ x = float(_x) #longfloat not really supported
sign = rfloat.copysign(1.0, x) < 0.0
if not rfloat.isfinite(x):
if rfloat.isinf(x):
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit