Author: Manuel Jacob
Branch: remove-remaining-smm
Changeset: r69330:a2d089c94859
Date: 2014-02-24 03:41 +0100
http://bitbucket.org/pypy/pypy/changeset/a2d089c94859/
Log: Kill last float SMMs.
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
@@ -9,7 +9,7 @@
from pypy.objspace.std.longobject import W_LongObject
from pypy.objspace.std.model import registerimplementation, W_Object
from pypy.objspace.std.register_all import register_all
-from pypy.objspace.std.stdtypedef import StdTypeDef, SMM
+from pypy.objspace.std.stdtypedef import StdTypeDef
from rpython.rlib import rarithmetic, rfloat
from rpython.rlib.rarithmetic import ovfcheck_float_to_int, intmask, LONG_BIT
from rpython.rlib.rfloat import (
@@ -20,11 +20,6 @@
from rpython.rlib.unroll import unrolling_iterable
-float_as_integer_ratio = SMM("as_integer_ratio", 1)
-float_is_integer = SMM("is_integer", 1)
-float_hex = SMM("hex", 1)
-
-
def detect_floatformat():
from rpython.rtyper.lltypesystem import rffi, lltype
buf = lltype.malloc(rffi.CCHARP.TO, 8, flavor='raw')
@@ -574,15 +569,70 @@
return space.w_NotImplemented
return w_lhs.descr_pow(space, self, w_third_arg)
- def descr_conjugate(self, space):
- return space.float(self)
-
def descr_get_real(self, space):
return space.float(self)
def descr_get_imag(self, space):
return space.wrap(0.0)
+ def descr_conjugate(self, space):
+ return space.float(self)
+
+ def descr_is_integer(self, space):
+ v = self.floatval
+ if not rfloat.isfinite(v):
+ return space.w_False
+ return space.wrap(math.floor(v) == v)
+
+ def descr_as_integer_ratio(self, space):
+ value = self.floatval
+ try:
+ num, den = float_as_rbigint_ratio(value)
+ except OverflowError:
+ w_msg = space.wrap("cannot pass infinity to as_integer_ratio()")
+ raise OperationError(space.w_OverflowError, w_msg)
+ except ValueError:
+ w_msg = space.wrap("cannot pass nan to as_integer_ratio()")
+ raise OperationError(space.w_ValueError, w_msg)
+
+ w_num = space.newlong_from_rbigint(num)
+ w_den = space.newlong_from_rbigint(den)
+ # Try to return int
+ return space.newtuple([space.int(w_num), space.int(w_den)])
+
+ def descr_hex(self, space):
+ value = self.floatval
+ if not isfinite(value):
+ return self.descr_str(space)
+ if value == 0.0:
+ if copysign(1., value) == -1.:
+ return space.wrap("-0x0.0p+0")
+ else:
+ return space.wrap("0x0.0p+0")
+ mant, exp = math.frexp(value)
+ shift = 1 - max(rfloat.DBL_MIN_EXP - exp, 0)
+ mant = math.ldexp(mant, shift)
+ mant = abs(mant)
+ exp -= shift
+ result = ['\0'] * ((TOHEX_NBITS - 1) // 4 + 2)
+ result[0] = _char_from_hex(int(mant))
+ mant -= int(mant)
+ result[1] = "."
+ for i in range((TOHEX_NBITS - 1) // 4):
+ mant *= 16.0
+ result[i + 2] = _char_from_hex(int(mant))
+ mant -= int(mant)
+ if exp < 0:
+ sign = "-"
+ else:
+ sign = "+"
+ exp = abs(exp)
+ s = ''.join(result)
+ if value < 0.0:
+ return space.wrap("-0x%sp%s%d" % (s, sign, exp))
+ else:
+ return space.wrap("0x%sp%s%d" % (s, sign, exp))
+
registerimplementation(W_FloatObject)
@@ -634,9 +684,12 @@
__pow__ = interp2app(W_FloatObject.descr_pow),
__rpow__ = interp2app(W_FloatObject.descr_rpow),
- conjugate = interp2app(W_FloatObject.descr_conjugate),
real = GetSetProperty(W_FloatObject.descr_get_real),
imag = GetSetProperty(W_FloatObject.descr_get_imag),
+ conjugate = interp2app(W_FloatObject.descr_conjugate),
+ is_integer = interp2app(W_FloatObject.descr_is_integer),
+ as_integer_ratio = interp2app(W_FloatObject.descr_as_integer_ratio),
+ hex = interp2app(W_FloatObject.descr_hex),
)
W_FloatObject.typedef.registermethods(globals())
@@ -646,39 +699,6 @@
TOHEX_NBITS = rfloat.DBL_MANT_DIG + 3 - (rfloat.DBL_MANT_DIG + 2) % 4
-def float_hex__Float(space, w_float):
- value = w_float.floatval
- if not isfinite(value):
- return w_float.descr_str(space)
- if value == 0.0:
- if copysign(1., value) == -1.:
- return space.wrap("-0x0.0p+0")
- else:
- return space.wrap("0x0.0p+0")
- mant, exp = math.frexp(value)
- shift = 1 - max(rfloat.DBL_MIN_EXP - exp, 0)
- mant = math.ldexp(mant, shift)
- mant = abs(mant)
- exp -= shift
- result = ['\0'] * ((TOHEX_NBITS - 1) // 4 + 2)
- result[0] = _char_from_hex(int(mant))
- mant -= int(mant)
- result[1] = "."
- for i in range((TOHEX_NBITS - 1) // 4):
- mant *= 16.0
- result[i + 2] = _char_from_hex(int(mant))
- mant -= int(mant)
- if exp < 0:
- sign = "-"
- else:
- sign = "+"
- exp = abs(exp)
- s = ''.join(result)
- if value < 0.0:
- return space.wrap("-0x%sp%s%d" % (s, sign, exp))
- else:
- return space.wrap("0x%sp%s%d" % (s, sign, exp))
-
def float2string(x, code, precision):
# we special-case explicitly inf and nan here
if isfinite(x):
@@ -873,26 +893,4 @@
return z
-def float_as_integer_ratio__Float(space, w_float):
- value = w_float.floatval
- try:
- num, den = float_as_rbigint_ratio(value)
- except OverflowError:
- w_msg = space.wrap("cannot pass infinity to as_integer_ratio()")
- raise OperationError(space.w_OverflowError, w_msg)
- except ValueError:
- w_msg = space.wrap("cannot pass nan to as_integer_ratio()")
- raise OperationError(space.w_ValueError, w_msg)
-
- w_num = space.newlong_from_rbigint(num)
- w_den = space.newlong_from_rbigint(den)
- # Try to return int
- return space.newtuple([space.int(w_num), space.int(w_den)])
-
-def float_is_integer__Float(space, w_float):
- v = w_float.floatval
- if not rfloat.isfinite(v):
- return space.w_False
- return space.wrap(math.floor(v) == v)
-
register_all(vars(), globals())
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit