Author: Manuel Jacob Branch: remove-remaining-smm Changeset: r69321:2ae7ef84292e Date: 2014-02-24 01:08 +0100 http://bitbucket.org/pypy/pypy/changeset/2ae7ef84292e/
Log: Kill floattype.py. diff --git a/pypy/module/micronumpy/interp_boxes.py b/pypy/module/micronumpy/interp_boxes.py --- a/pypy/module/micronumpy/interp_boxes.py +++ b/pypy/module/micronumpy/interp_boxes.py @@ -3,7 +3,7 @@ from pypy.interpreter.gateway import interp2app, unwrap_spec from pypy.interpreter.typedef import TypeDef, GetSetProperty from pypy.objspace.std.bytesobject import W_BytesObject -from pypy.objspace.std.floattype import float_typedef +from pypy.objspace.std.floatobject import W_FloatObject from pypy.objspace.std.unicodeobject import W_UnicodeObject from pypy.objspace.std.intobject import W_IntObject from pypy.objspace.std.complexobject import W_ComplexObject @@ -750,7 +750,7 @@ __reduce__ = interp2app(W_Float32Box.descr_reduce), ) -W_Float64Box.typedef = TypeDef("float64", (W_FloatingBox.typedef, float_typedef), +W_Float64Box.typedef = TypeDef("float64", (W_FloatingBox.typedef, W_FloatObject.typedef), __module__ = "numpy", __new__ = interp2app(W_Float64Box.descr__new__.im_func), __reduce__ = interp2app(W_Float64Box.descr_reduce), 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 @@ -1,24 +1,114 @@ +import math import operator +import sys from pypy.interpreter.error import OperationError, oefmt -from pypy.objspace.std import model, newformat -from pypy.objspace.std.floattype import float_typedef, W_AbstractFloatObject +from pypy.interpreter.gateway import interp2app, unwrap_spec, WrappedDefault, interpindirect2app +from pypy.interpreter.typedef import GetSetProperty +from pypy.objspace.std import newformat +from pypy.objspace.std.longobject import W_LongObject from pypy.objspace.std.multimethod import FailedToImplementArgs from pypy.objspace.std.model import registerimplementation, W_Object from pypy.objspace.std.register_all import register_all -from pypy.objspace.std.noneobject import W_NoneObject -from pypy.objspace.std.longobject import W_LongObject +from pypy.objspace.std.stdtypedef import StdTypeDef, SMM +from rpython.rlib import rarithmetic, rfloat from rpython.rlib.rarithmetic import ovfcheck_float_to_int, intmask, LONG_BIT from rpython.rlib.rfloat import ( isinf, isnan, isfinite, INFINITY, NAN, copysign, formatd, DTSF_ADD_DOT_0, DTSF_STR_PRECISION, float_as_rbigint_ratio) from rpython.rlib.rbigint import rbigint -from rpython.rlib import rfloat +from rpython.rlib.rstring import ParseStringError from rpython.tool.sourcetools import func_with_new_name +from rpython.rlib.unroll import unrolling_iterable +from pypy.objspace.std.intobject import W_IntObject -import math -from pypy.objspace.std.intobject import W_IntObject + +float_as_integer_ratio = SMM("as_integer_ratio", 1) +float_is_integer = SMM("is_integer", 1) +float_hex = SMM("hex", 1) + + +class W_AbstractFloatObject(W_Object): + __slots__ = () + + def is_w(self, space, w_other): + from rpython.rlib.longlong2float import float2longlong + if not isinstance(w_other, W_AbstractFloatObject): + return False + if self.user_overridden_class or w_other.user_overridden_class: + return self is w_other + one = float2longlong(space.float_w(self)) + two = float2longlong(space.float_w(w_other)) + return one == two + + def immutable_unique_id(self, space): + if self.user_overridden_class: + return None + from rpython.rlib.longlong2float import float2longlong + from pypy.objspace.std.model import IDTAG_FLOAT as tag + val = float2longlong(space.float_w(self)) + b = rbigint.fromrarith_int(val) + b = b.lshift(3).or_(rbigint.fromint(tag)) + return space.newlong_from_rbigint(b) + + def int(self, space): + raise NotImplementedError + + +def detect_floatformat(): + from rpython.rtyper.lltypesystem import rffi, lltype + buf = lltype.malloc(rffi.CCHARP.TO, 8, flavor='raw') + rffi.cast(rffi.DOUBLEP, buf)[0] = 9006104071832581.0 + packed = rffi.charpsize2str(buf, 8) + if packed == "\x43\x3f\xff\x01\x02\x03\x04\x05": + double_format = 'IEEE, big-endian' + elif packed == "\x05\x04\x03\x02\x01\xff\x3f\x43": + double_format = 'IEEE, little-endian' + else: + double_format = 'unknown' + lltype.free(buf, flavor='raw') + # + buf = lltype.malloc(rffi.CCHARP.TO, 4, flavor='raw') + rffi.cast(rffi.FLOATP, buf)[0] = rarithmetic.r_singlefloat(16711938.0) + packed = rffi.charpsize2str(buf, 4) + if packed == "\x4b\x7f\x01\x02": + float_format = 'IEEE, big-endian' + elif packed == "\x02\x01\x7f\x4b": + float_format = 'IEEE, little-endian' + else: + float_format = 'unknown' + lltype.free(buf, flavor='raw') + + return double_format, float_format + +_double_format, _float_format = detect_floatformat() + + +def _string_to_float(space, w_source, string): + try: + return rfloat.string_to_float(string) + except ParseStringError as e: + from pypy.objspace.std.intobject import wrap_parsestringerror + raise wrap_parsestringerror(space, e, w_source) + + +_alpha = zip("abcdef", range(10, 16)) + zip("ABCDEF", range(10, 16)) +_hex_to_int = zip("0123456789", range(10)) + _alpha +_hex_to_int_iterable = unrolling_iterable(_hex_to_int) + +def _hex_from_char(c): + for h, v in _hex_to_int_iterable: + if h == c: + return v + return -1 + +def _hex_digit(s, j, co_end, float_digits): + if j < float_digits: + i = co_end - j + else: + i = co_end - 1 - j + return _hex_from_char(s[i]) class W_FloatObject(W_AbstractFloatObject): @@ -26,8 +116,6 @@ The constructor takes an RPython float as an argument.""" _immutable_fields_ = ['floatval'] - typedef = float_typedef - def __init__(self, floatval): self.floatval = floatval @@ -51,8 +139,218 @@ def __repr__(self): return "<W_FloatObject(%f)>" % self.floatval + @staticmethod + @unwrap_spec(w_x=WrappedDefault(0.0)) + def descr__new__(space, w_floattype, w_x): + from pypy.objspace.std.floatobject import W_FloatObject + w_value = w_x # 'x' is the keyword argument name in CPython + if space.lookup(w_value, "__float__") is not None: + w_obj = space.float(w_value) + if space.is_w(w_floattype, space.w_float): + return w_obj + value = space.float_w(w_obj) + elif (space.isinstance_w(w_value, space.w_str) or + space.isinstance_w(w_value, space.w_bytearray)): + value = _string_to_float(space, w_value, space.bufferstr_w(w_value)) + elif space.isinstance_w(w_value, space.w_unicode): + from unicodeobject import unicode_to_decimal_w + value = _string_to_float(space, w_value, + unicode_to_decimal_w(space, w_value)) + else: + value = space.float_w(w_x) + w_obj = space.allocate_instance(W_FloatObject, w_floattype) + W_FloatObject.__init__(w_obj, value) + return w_obj + + @staticmethod + @unwrap_spec(s=str) + def descr_fromhex(space, w_cls, s): + length = len(s) + i = 0 + value = 0.0 + while i < length and s[i].isspace(): + i += 1 + if i == length: + raise OperationError(space.w_ValueError, + space.wrap("invalid hex string")) + sign = 1 + if s[i] == "-": + sign = -1 + i += 1 + elif s[i] == "+": + i += 1 + if length == i: + raise OperationError(space.w_ValueError, + space.wrap("invalid hex string")) + if s[i] == "i" or s[i] == "I": + i += 1 + if length - i >= 2 and s[i:i + 2].lower() == "nf": + i += 2 + value = rfloat.INFINITY + if length - i >= 5 and s[i:i + 5].lower() == "inity": + i += 5 + elif s[i] == "n" or s[i] == "N": + i += 1 + if length - i >= 2 and s[i:i + 2].lower() == "an": + i += 2 + value = rfloat.NAN + else: + if (s[i] == "0" and length - i > 1 and + (s[i + 1] == "x" or s[i + 1] == "X")): + i += 2 + co_start = i + while i < length and _hex_from_char(s[i]) >= 0: + i += 1 + whole_end = i + if i < length and s[i] == ".": + i += 1 + while i < length and _hex_from_char(s[i]) >= 0: + i += 1 + co_end = i - 1 + else: + co_end = i + total_digits = co_end - co_start + float_digits = co_end - whole_end + if not total_digits: + raise OperationError(space.w_ValueError, + space.wrap("invalid hex string")) + const_one = rfloat.DBL_MIN_EXP - rfloat.DBL_MANT_DIG + sys.maxint // 2 + const_two = sys.maxint // 2 + 1 - rfloat.DBL_MAX_EXP + if total_digits > min(const_one, const_two) // 4: + raise OperationError(space.w_ValueError, space.wrap("way too long")) + if i < length and (s[i] == "p" or s[i] == "P"): + i += 1 + if i == length: + raise OperationError(space.w_ValueError, + space.wrap("invalid hex string")) + exp_sign = 1 + if s[i] == "-" or s[i] == "+": + if s[i] == "-": + exp_sign = -1 + i += 1 + if i == length: + raise OperationError(space.w_ValueError, + space.wrap("invalid hex string")) + if not s[i].isdigit(): + raise OperationError(space.w_ValueError, + space.wrap("invalid hex string")) + exp = ord(s[i]) - ord('0') + i += 1 + while i < length and s[i].isdigit(): + exp = exp * 10 + (ord(s[i]) - ord('0')) + if exp >= (sys.maxint-9) // 10: + if exp_sign > 0: + exp_sign = 2 # overflow in positive numbers + else: + exp_sign = -2 # overflow in negative numbers + i += 1 + if exp_sign == -1: + exp = -exp + elif exp_sign == -2: + exp = -sys.maxint / 2 + elif exp_sign == 2: + exp = sys.maxint / 2 + else: + exp = 0 + while (total_digits and + _hex_digit(s, total_digits - 1, co_end, float_digits) == 0): + total_digits -= 1 + if not total_digits or exp <= -sys.maxint / 2: + value = 0.0 + elif exp >= sys.maxint // 2: + raise OperationError(space.w_OverflowError, space.wrap("too large")) + else: + exp -= 4 * float_digits + top_exp = exp + 4 * (total_digits - 1) + digit = _hex_digit(s, total_digits - 1, co_end, float_digits) + while digit: + top_exp += 1 + digit //= 2 + if top_exp < rfloat.DBL_MIN_EXP - rfloat.DBL_MANT_DIG: + value = 0.0 + elif top_exp > rfloat.DBL_MAX_EXP: + raise OperationError(space.w_OverflowError, + space.wrap("too large")) + else: + lsb = max(top_exp, rfloat.DBL_MIN_EXP) - rfloat.DBL_MANT_DIG + value = 0 + if exp >= lsb: + for j in range(total_digits - 1, -1, -1): + value = 16.0 * value + _hex_digit(s, j, co_end, + float_digits) + value = math.ldexp(value, exp) + else: + half_eps = 1 << ((lsb - exp - 1) % 4) + key_digit = (lsb - exp - 1) // 4 + for j in range(total_digits - 1, key_digit, -1): + value = 16.0 * value + _hex_digit(s, j, co_end, + float_digits) + digit = _hex_digit(s, key_digit, co_end, float_digits) + value = 16.0 * value + (digit & (16 - 2*half_eps)) + if digit & half_eps: + round_up = False + if (digit & (3 * half_eps - 1) or + (half_eps == 8 and + _hex_digit(s, key_digit + 1, co_end, float_digits) & 1)): + round_up = True + else: + for j in range(key_digit - 1, -1, -1): + if _hex_digit(s, j, co_end, float_digits): + round_up = True + break + if round_up: + value += 2 * half_eps + mant_dig = rfloat.DBL_MANT_DIG + if (top_exp == rfloat.DBL_MAX_EXP and + value == math.ldexp(2 * half_eps, mant_dig)): + raise OperationError(space.w_OverflowError, + space.wrap("too large")) + value = math.ldexp(value, (exp + 4*key_digit)) + while i < length and s[i].isspace(): + i += 1 + if i != length: + raise OperationError(space.w_ValueError, + space.wrap("invalid hex string")) + w_float = space.wrap(sign * value) + return space.call_function(w_cls, w_float) + + 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) + + @staticmethod + @unwrap_spec(kind=str) + def descr___getformat__(space, w_cls, kind): + if kind == "float": + return space.wrap(_float_format) + elif kind == "double": + return space.wrap(_double_format) + raise OperationError(space.w_ValueError, + space.wrap("only float and double are valid")) + + registerimplementation(W_FloatObject) +W_FloatObject.typedef = StdTypeDef("float", + __doc__ = '''float(x) -> floating point number + +Convert a string or number to a floating point number, if possible.''', + __new__ = interp2app(W_FloatObject.descr__new__), + __getformat__ = interp2app(W_FloatObject.descr___getformat__, as_classmethod=True), + fromhex = interp2app(W_FloatObject.descr_fromhex, as_classmethod=True), + conjugate = interp2app(W_FloatObject.descr_conjugate), + real = GetSetProperty(W_FloatObject.descr_get_real), + imag = GetSetProperty(W_FloatObject.descr_get_imag), + __int__ = interpindirect2app(W_AbstractFloatObject.int), +) +W_FloatObject.typedef.registermethods(globals()) + + # bool-to-float delegation def delegate_Bool2Float(space, w_bool): return W_FloatObject(float(w_bool.intval)) @@ -560,5 +858,4 @@ return space.w_False return space.wrap(math.floor(v) == v) -from pypy.objspace.std import floattype -register_all(vars(), floattype) +register_all(vars(), globals()) diff --git a/pypy/objspace/std/floattype.py b/pypy/objspace/std/floattype.py deleted file mode 100644 --- a/pypy/objspace/std/floattype.py +++ /dev/null @@ -1,307 +0,0 @@ -import math -import sys -from rpython.rlib.unroll import unrolling_iterable -from rpython.rlib import rfloat, rarithmetic -from pypy.interpreter import typedef -from pypy.interpreter.gateway import interp2app, unwrap_spec, WrappedDefault,\ - interpindirect2app -from pypy.interpreter.error import OperationError -from pypy.objspace.std.register_all import register_all -from pypy.objspace.std.stdtypedef import StdTypeDef, SMM -from pypy.objspace.std.model import W_Object -from rpython.rlib.rbigint import rbigint -from rpython.rlib.rstring import ParseStringError - - -float_as_integer_ratio = SMM("as_integer_ratio", 1) -float_is_integer = SMM("is_integer", 1) -float_hex = SMM("hex", 1) - -def descr_conjugate(space, w_float): - return space.float(w_float) - -register_all(vars(), globals()) - - -@unwrap_spec(w_x = WrappedDefault(0.0)) -def descr__new__(space, w_floattype, w_x): - from pypy.objspace.std.floatobject import W_FloatObject - w_value = w_x # 'x' is the keyword argument name in CPython - if space.lookup(w_value, "__float__") is not None: - w_obj = space.float(w_value) - if space.is_w(w_floattype, space.w_float): - return w_obj - value = space.float_w(w_obj) - elif (space.isinstance_w(w_value, space.w_str) or - space.isinstance_w(w_value, space.w_bytearray)): - value = _string_to_float(space, w_value, space.bufferstr_w(w_value)) - elif space.isinstance_w(w_value, space.w_unicode): - from unicodeobject import unicode_to_decimal_w - value = _string_to_float(space, w_value, - unicode_to_decimal_w(space, w_value)) - else: - value = space.float_w(w_x) - w_obj = space.allocate_instance(W_FloatObject, w_floattype) - W_FloatObject.__init__(w_obj, value) - return w_obj - - -def _string_to_float(space, w_source, string): - try: - return rfloat.string_to_float(string) - except ParseStringError as e: - from pypy.objspace.std.intobject import wrap_parsestringerror - raise wrap_parsestringerror(space, e, w_source) - - -def detect_floatformat(): - from rpython.rtyper.lltypesystem import rffi, lltype - buf = lltype.malloc(rffi.CCHARP.TO, 8, flavor='raw') - rffi.cast(rffi.DOUBLEP, buf)[0] = 9006104071832581.0 - packed = rffi.charpsize2str(buf, 8) - if packed == "\x43\x3f\xff\x01\x02\x03\x04\x05": - double_format = 'IEEE, big-endian' - elif packed == "\x05\x04\x03\x02\x01\xff\x3f\x43": - double_format = 'IEEE, little-endian' - else: - double_format = 'unknown' - lltype.free(buf, flavor='raw') - # - buf = lltype.malloc(rffi.CCHARP.TO, 4, flavor='raw') - rffi.cast(rffi.FLOATP, buf)[0] = rarithmetic.r_singlefloat(16711938.0) - packed = rffi.charpsize2str(buf, 4) - if packed == "\x4b\x7f\x01\x02": - float_format = 'IEEE, big-endian' - elif packed == "\x02\x01\x7f\x4b": - float_format = 'IEEE, little-endian' - else: - float_format = 'unknown' - lltype.free(buf, flavor='raw') - - return double_format, float_format - -_double_format, _float_format = detect_floatformat() - -@unwrap_spec(kind=str) -def descr___getformat__(space, w_cls, kind): - if kind == "float": - return space.wrap(_float_format) - elif kind == "double": - return space.wrap(_double_format) - raise OperationError(space.w_ValueError, - space.wrap("only float and double are valid")) - -_alpha = zip("abcdef", range(10, 16)) + zip("ABCDEF", range(10, 16)) -_hex_to_int = zip("0123456789", range(10)) + _alpha -_hex_to_int_iterable = unrolling_iterable(_hex_to_int) -def _hex_from_char(c): - for h, v in _hex_to_int_iterable: - if h == c: - return v - return -1 - -def _hex_digit(s, j, co_end, float_digits): - if j < float_digits: - i = co_end - j - else: - i = co_end - 1 - j - return _hex_from_char(s[i]) - -@unwrap_spec(s=str) -def descr_fromhex(space, w_cls, s): - length = len(s) - i = 0 - value = 0.0 - while i < length and s[i].isspace(): - i += 1 - if i == length: - raise OperationError(space.w_ValueError, - space.wrap("invalid hex string")) - sign = 1 - if s[i] == "-": - sign = -1 - i += 1 - elif s[i] == "+": - i += 1 - if length == i: - raise OperationError(space.w_ValueError, - space.wrap("invalid hex string")) - if s[i] == "i" or s[i] == "I": - i += 1 - if length - i >= 2 and s[i:i + 2].lower() == "nf": - i += 2 - value = rfloat.INFINITY - if length - i >= 5 and s[i:i + 5].lower() == "inity": - i += 5 - elif s[i] == "n" or s[i] == "N": - i += 1 - if length - i >= 2 and s[i:i + 2].lower() == "an": - i += 2 - value = rfloat.NAN - else: - if (s[i] == "0" and length - i > 1 and - (s[i + 1] == "x" or s[i + 1] == "X")): - i += 2 - co_start = i - while i < length and _hex_from_char(s[i]) >= 0: - i += 1 - whole_end = i - if i < length and s[i] == ".": - i += 1 - while i < length and _hex_from_char(s[i]) >= 0: - i += 1 - co_end = i - 1 - else: - co_end = i - total_digits = co_end - co_start - float_digits = co_end - whole_end - if not total_digits: - raise OperationError(space.w_ValueError, - space.wrap("invalid hex string")) - const_one = rfloat.DBL_MIN_EXP - rfloat.DBL_MANT_DIG + sys.maxint // 2 - const_two = sys.maxint // 2 + 1 - rfloat.DBL_MAX_EXP - if total_digits > min(const_one, const_two) // 4: - raise OperationError(space.w_ValueError, space.wrap("way too long")) - if i < length and (s[i] == "p" or s[i] == "P"): - i += 1 - if i == length: - raise OperationError(space.w_ValueError, - space.wrap("invalid hex string")) - exp_sign = 1 - if s[i] == "-" or s[i] == "+": - if s[i] == "-": - exp_sign = -1 - i += 1 - if i == length: - raise OperationError(space.w_ValueError, - space.wrap("invalid hex string")) - if not s[i].isdigit(): - raise OperationError(space.w_ValueError, - space.wrap("invalid hex string")) - exp = ord(s[i]) - ord('0') - i += 1 - while i < length and s[i].isdigit(): - exp = exp * 10 + (ord(s[i]) - ord('0')) - if exp >= (sys.maxint-9) // 10: - if exp_sign > 0: - exp_sign = 2 # overflow in positive numbers - else: - exp_sign = -2 # overflow in negative numbers - i += 1 - if exp_sign == -1: - exp = -exp - elif exp_sign == -2: - exp = -sys.maxint / 2 - elif exp_sign == 2: - exp = sys.maxint / 2 - else: - exp = 0 - while (total_digits and - _hex_digit(s, total_digits - 1, co_end, float_digits) == 0): - total_digits -= 1 - if not total_digits or exp <= -sys.maxint / 2: - value = 0.0 - elif exp >= sys.maxint // 2: - raise OperationError(space.w_OverflowError, space.wrap("too large")) - else: - exp -= 4 * float_digits - top_exp = exp + 4 * (total_digits - 1) - digit = _hex_digit(s, total_digits - 1, co_end, float_digits) - while digit: - top_exp += 1 - digit //= 2 - if top_exp < rfloat.DBL_MIN_EXP - rfloat.DBL_MANT_DIG: - value = 0.0 - elif top_exp > rfloat.DBL_MAX_EXP: - raise OperationError(space.w_OverflowError, - space.wrap("too large")) - else: - lsb = max(top_exp, rfloat.DBL_MIN_EXP) - rfloat.DBL_MANT_DIG - value = 0 - if exp >= lsb: - for j in range(total_digits - 1, -1, -1): - value = 16.0 * value + _hex_digit(s, j, co_end, - float_digits) - value = math.ldexp(value, exp) - else: - half_eps = 1 << ((lsb - exp - 1) % 4) - key_digit = (lsb - exp - 1) // 4 - for j in range(total_digits - 1, key_digit, -1): - value = 16.0 * value + _hex_digit(s, j, co_end, - float_digits) - digit = _hex_digit(s, key_digit, co_end, float_digits) - value = 16.0 * value + (digit & (16 - 2*half_eps)) - if digit & half_eps: - round_up = False - if (digit & (3 * half_eps - 1) or - (half_eps == 8 and - _hex_digit(s, key_digit + 1, co_end, float_digits) & 1)): - round_up = True - else: - for j in range(key_digit - 1, -1, -1): - if _hex_digit(s, j, co_end, float_digits): - round_up = True - break - if round_up: - value += 2 * half_eps - mant_dig = rfloat.DBL_MANT_DIG - if (top_exp == rfloat.DBL_MAX_EXP and - value == math.ldexp(2 * half_eps, mant_dig)): - raise OperationError(space.w_OverflowError, - space.wrap("too large")) - value = math.ldexp(value, (exp + 4*key_digit)) - while i < length and s[i].isspace(): - i += 1 - if i != length: - raise OperationError(space.w_ValueError, - space.wrap("invalid hex string")) - w_float = space.wrap(sign * value) - return space.call_function(w_cls, w_float) - -def descr_get_real(space, w_obj): - return space.float(w_obj) - -def descr_get_imag(space, w_obj): - return space.wrap(0.0) - -# ____________________________________________________________ - -class W_AbstractFloatObject(W_Object): - __slots__ = () - - def is_w(self, space, w_other): - from rpython.rlib.longlong2float import float2longlong - if not isinstance(w_other, W_AbstractFloatObject): - return False - if self.user_overridden_class or w_other.user_overridden_class: - return self is w_other - one = float2longlong(space.float_w(self)) - two = float2longlong(space.float_w(w_other)) - return one == two - - def immutable_unique_id(self, space): - if self.user_overridden_class: - return None - from rpython.rlib.longlong2float import float2longlong - from pypy.objspace.std.model import IDTAG_FLOAT as tag - val = float2longlong(space.float_w(self)) - b = rbigint.fromrarith_int(val) - b = b.lshift(3).or_(rbigint.fromint(tag)) - return space.newlong_from_rbigint(b) - - def int(self, space): - raise NotImplementedError - -float_typedef = StdTypeDef("float", - __doc__ = '''float(x) -> floating point number - -Convert a string or number to a floating point number, if possible.''', - __new__ = interp2app(descr__new__), - __getformat__ = interp2app(descr___getformat__, as_classmethod=True), - fromhex = interp2app(descr_fromhex, as_classmethod=True), - conjugate = interp2app(descr_conjugate), - real = typedef.GetSetProperty(descr_get_real), - imag = typedef.GetSetProperty(descr_get_imag), - __int__ = interpindirect2app(W_AbstractFloatObject.int), -) -float_typedef.registermethods(globals()) diff --git a/pypy/objspace/std/model.py b/pypy/objspace/std/model.py --- a/pypy/objspace/std/model.py +++ b/pypy/objspace/std/model.py @@ -32,7 +32,6 @@ # All the Python types that we want to provide in this StdObjSpace class result: from pypy.objspace.std.objecttype import object_typedef - from pypy.objspace.std.floattype import float_typedef from pypy.objspace.std.typeobject import type_typedef from pypy.objspace.std.slicetype import slice_typedef from pypy.objspace.std.nonetype import none_typedef @@ -57,7 +56,6 @@ from pypy.objspace.std import typeobject from pypy.objspace.std import sliceobject from pypy.objspace.std import longobject - from pypy.objspace.std import complexobject from pypy.objspace.std import noneobject from pypy.objspace.std import iterobject from pypy.objspace.std import unicodeobject @@ -82,6 +80,7 @@ self.pythontypes.append(intobject.W_IntObject.typedef) self.pythontypes.append(boolobject.W_BoolObject.typedef) self.pythontypes.append(longobject.W_LongObject.typedef) + self.pythontypes.append(floatobject.W_FloatObject.typedef) self.pythontypes.append(complexobject.W_ComplexObject.typedef) # the set of implementation types _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit