Author: Ronan Lamy <[email protected]>
Branch: kill-ootype
Changeset: r65708:7a0e4c894994
Date: 2013-07-27 13:24 +0100
http://bitbucket.org/pypy/pypy/changeset/7a0e4c894994/
Log: Kill USE_SHORT_FLOAT_REPR (make it always True)
diff --git a/pypy/module/sys/system.py b/pypy/module/sys/system.py
--- a/pypy/module/sys/system.py
+++ b/pypy/module/sys/system.py
@@ -57,4 +57,4 @@
return space.call_function(w_long_info, space.newtuple(info_w))
def get_float_repr_style(space):
- return space.wrap("short" if rfloat.USE_SHORT_FLOAT_REPR else "legacy")
+ return space.wrap("short")
diff --git a/rpython/config/translationoption.py
b/rpython/config/translationoption.py
--- a/rpython/config/translationoption.py
+++ b/rpython/config/translationoption.py
@@ -321,13 +321,6 @@
'jit': DEFL_GC + ' extraopts jit',
}
-def final_check_config(config):
- # XXX: this should be a real config option, but it is hard to refactor it;
- # instead, we "just" patch it from here
- from rpython.rlib import rfloat
- if config.translation.type_system == 'ootype':
- rfloat.USE_SHORT_FLOAT_REPR = False
-
def set_opt_level(config, level):
"""Apply optimization suggestions on the 'config'.
The optimizations depend on the selected level and possibly on the backend.
diff --git a/rpython/rlib/rfloat.py b/rpython/rlib/rfloat.py
--- a/rpython/rlib/rfloat.py
+++ b/rpython/rlib/rfloat.py
@@ -9,8 +9,6 @@
from rpython.translator.tool.cbuild import ExternalCompilationInfo
-USE_SHORT_FLOAT_REPR = True # XXX make it a translation option?
-
class CConfig:
_compilation_info_ = ExternalCompilationInfo(includes=["float.h"])
@@ -61,80 +59,8 @@
raise ParseStringError("invalid literal for float(): '%s'" % s)
def rstring_to_float(s):
- return rstring_to_float_impl(s)
-
-def rstring_to_float_impl(s):
- if USE_SHORT_FLOAT_REPR:
- from rpython.rlib.rdtoa import strtod
- return strtod(s)
- sign, before_point, after_point, exponent = break_up_float(s)
- if not before_point and not after_point:
- raise ValueError
- return parts_to_float(sign, before_point, after_point, exponent)
-
-register_external(rstring_to_float, [SomeString(can_be_None=False)], float,
- llimpl=rstring_to_float_impl, sandboxsafe=True)
-
-
-# float as string -> sign, beforept, afterpt, exponent
-def break_up_float(s):
- i = 0
-
- sign = ''
- before_point = ''
- after_point = ''
- exponent = ''
-
- if s[i] in '+-':
- sign = s[i]
- i += 1
-
- while i < len(s) and s[i] in '0123456789':
- before_point += s[i]
- i += 1
-
- if i == len(s):
- return sign, before_point, after_point, exponent
-
- if s[i] == '.':
- i += 1
- while i < len(s) and s[i] in '0123456789':
- after_point += s[i]
- i += 1
-
- if i == len(s):
- return sign, before_point, after_point, exponent
-
- if s[i] not in 'eE':
- raise ValueError
-
- i += 1
- if i == len(s):
- raise ValueError
-
- if s[i] in '-+':
- exponent += s[i]
- i += 1
-
- if i == len(s):
- raise ValueError
-
- while i < len(s) and s[i] in '0123456789':
- exponent += s[i]
- i += 1
-
- if i != len(s):
- raise ValueError
-
- return sign, before_point, after_point, exponent
-
-# string -> float helper
-
-def parts_to_float(sign, beforept, afterpt, exponent):
- "NOT_RPYTHON"
- if not exponent:
- exponent = '0'
- return float("%s%s.%se%s" % (sign, beforept, afterpt, exponent))
+ from rpython.rlib.rdtoa import strtod
+ return strtod(s)
# float -> string
@@ -148,42 +74,10 @@
DIST_NAN = 2
DIST_INFINITY = 3
-# Equivalent to CPython's PyOS_double_to_string
-def _formatd(x, code, precision, flags):
- "NOT_RPYTHON"
- if flags & DTSF_ALT:
- alt = '#'
- else:
- alt = ''
-
- if code == 'r':
- fmt = "%r"
- else:
- fmt = "%%%s.%d%s" % (alt, precision, code)
- s = fmt % (x,)
-
- if flags & DTSF_ADD_DOT_0:
- # We want float numbers to be recognizable as such,
- # i.e., they should contain a decimal point or an exponent.
- # However, %g may print the number as an integer;
- # in such cases, we append ".0" to the string.
- for c in s:
- if c in '.eE':
- break
- else:
- s += '.0'
- elif code == 'r' and s.endswith('.0'):
- s = s[:-2]
-
- return s
-
@objectmodel.enforceargs(float, SomeChar(), int, int)
def formatd(x, code, precision, flags=0):
- if USE_SHORT_FLOAT_REPR:
- from rpython.rlib.rdtoa import dtoa_formatd
- return dtoa_formatd(x, code, precision, flags)
- else:
- return _formatd(x, code, precision, flags)
+ from rpython.rlib.rdtoa import dtoa_formatd
+ return dtoa_formatd(x, code, precision, flags)
def double_to_string(value, tp, precision, flags):
if isfinite(value):
@@ -200,12 +94,6 @@
Specify half_even=True to round half even instead.
"""
- if USE_SHORT_FLOAT_REPR:
- return round_double_short_repr(value, ndigits, half_even)
- else:
- return round_double_fallback_repr(value, ndigits, half_even)
-
-def round_double_short_repr(value, ndigits, half_even):
# The basic idea is very simple: convert and round the double to
# a decimal string using _Py_dg_dtoa, then convert that decimal
# string back to a double with _Py_dg_strtod. There's one minor
@@ -290,46 +178,6 @@
return sign * rstring_to_float(strvalue)
-# fallback version, to be used when correctly rounded
-# binary<->decimal conversions aren't available
-def round_double_fallback_repr(value, ndigits, half_even):
- if ndigits >= 0:
- if ndigits > 22:
- # pow1 and pow2 are each safe from overflow, but
- # pow1*pow2 ~= pow(10.0, ndigits) might overflow
- pow1 = math.pow(10.0, ndigits - 22)
- pow2 = 1e22
- else:
- pow1 = math.pow(10.0, ndigits)
- pow2 = 1.0
-
- y = (value * pow1) * pow2
- # if y overflows, then rounded value is exactly x
- if isinf(y):
- return value
-
- else:
- pow1 = math.pow(10.0, -ndigits);
- pow2 = 1.0 # unused; for translation
- y = value / pow1
-
- if half_even:
- z = round_away(y)
- if math.fabs(y - z) == 0.5:
- z = 2.0 * round_away(y / 2.0)
- else:
- if y >= 0.0:
- z = math.floor(y + 0.5)
- else:
- z = math.ceil(y - 0.5)
- if math.fabs(y - z) == 1.0: # obscure case, see the test
- z = y
-
- if ndigits >= 0:
- z = (z / pow2) / pow1
- else:
- z *= pow1
- return z
INFINITY = 1e200 * 1e200
NAN = abs(INFINITY / INFINITY) # bah, INF/INF gives us -NAN?
diff --git a/rpython/rlib/test/test_rfloat.py b/rpython/rlib/test/test_rfloat.py
--- a/rpython/rlib/test/test_rfloat.py
+++ b/rpython/rlib/test/test_rfloat.py
@@ -1,7 +1,6 @@
import sys, py
from rpython.rlib.rfloat import float_as_rbigint_ratio
-from rpython.rlib.rfloat import break_up_float
from rpython.rlib.rfloat import copysign
from rpython.rlib.rfloat import round_away
from rpython.rlib.rfloat import round_double
@@ -88,32 +87,11 @@
def test_round_half_even():
from rpython.rlib import rfloat
- for func in (rfloat.round_double_short_repr,
- rfloat.round_double_fallback_repr):
- # 2.x behavior
- assert func(2.5, 0, False) == 3.0
- # 3.x behavior
- assert func(2.5, 0, True) == 2.0
-
-def test_break_up_float():
- assert break_up_float('1') == ('', '1', '', '')
- assert break_up_float('+1') == ('+', '1', '', '')
- assert break_up_float('-1') == ('-', '1', '', '')
-
- assert break_up_float('.5') == ('', '', '5', '')
-
- assert break_up_float('1.2e3') == ('', '1', '2', '3')
- assert break_up_float('1.2e+3') == ('', '1', '2', '+3')
- assert break_up_float('1.2e-3') == ('', '1', '2', '-3')
-
- # some that will get thrown out on return:
- assert break_up_float('.') == ('', '', '', '')
- assert break_up_float('+') == ('+', '', '', '')
- assert break_up_float('-') == ('-', '', '', '')
- assert break_up_float('e1') == ('', '', '', '1')
-
- py.test.raises(ValueError, break_up_float, 'e')
-
+ func = rfloat.round_double
+ # 2.x behavior
+ assert func(2.5, 0, False) == 3.0
+ # 3.x behavior
+ assert func(2.5, 0, True) == 2.0
def test_float_as_rbigint_ratio():
for f, ratio in [
diff --git a/rpython/rtyper/extfuncregistry.py
b/rpython/rtyper/extfuncregistry.py
--- a/rpython/rtyper/extfuncregistry.py
+++ b/rpython/rtyper/extfuncregistry.py
@@ -85,7 +85,3 @@
llimpl = func_with_new_name(func, name)
register_external(func, args, res, 'll_os_path.ll_%s' % name,
llimpl=llimpl, sandboxsafe=True)
-
-# -------------------- strtod functions ----------------------
-
-from rpython.rtyper.module import ll_strtod
diff --git a/rpython/rtyper/module/ll_strtod.py
b/rpython/rtyper/module/ll_strtod.py
deleted file mode 100644
--- a/rpython/rtyper/module/ll_strtod.py
+++ /dev/null
@@ -1,107 +0,0 @@
-
-import py
-from rpython.rtyper.extfunc import BaseLazyRegistering, extdef, registering
-from rpython.rlib import rfloat
-from rpython.rtyper.lltypesystem import lltype, rffi
-from rpython.rlib import rposix
-from rpython.translator.tool.cbuild import ExternalCompilationInfo
-from rpython.conftest import cdir
-from rpython.annotator.model import SomeString
-
-class CConfig:
- _compilation_info_ = ExternalCompilationInfo(
- includes = ['src/ll_strtod.h'],
- include_dirs = [str(py.path.local(cdir))],
- separate_module_sources = ['#include <src/ll_strtod.c>'],
- export_symbols = ['LL_strtod_formatd', 'LL_strtod_parts_to_float'],
- )
-
-class RegisterStrtod(BaseLazyRegistering):
- def __init__(self):
- self.configure(CConfig)
-
- @registering(rfloat._formatd)
- def register_formatd(self):
- ll_strtod = self.llexternal('LL_strtod_formatd',
- [rffi.DOUBLE, rffi.CHAR, rffi.INT],
rffi.CCHARP,
- sandboxsafe=True, threadsafe=False)
-
- # Like PyOS_double_to_string(), when PY_NO_SHORT_FLOAT_REPR is defined
- def llimpl(x, code, precision, flags):
- upper = False
- if code == 'r':
- code = 'g'
- precision = 17
- elif code == 'E':
- code = 'e'
- upper = True
- elif code == 'F':
- code = 'f'
- upper = True
- elif code == 'G':
- code = 'g'
- upper = True
-
- res = ll_strtod(x, code, precision)
- s = rffi.charp2str(res)
-
- if flags & rfloat.DTSF_ADD_DOT_0:
- s = ensure_decimal_point(s, precision)
-
- # Add sign when requested
- if flags & rfloat.DTSF_SIGN and s[0] != '-':
- s = '+' + s
-
- # Convert to upper case
- if upper:
- s = s.upper()
-
- return s
-
- return extdef([float, lltype.Char, int, int],
- SomeString(can_be_None=True),
- 'll_strtod.ll_strtod_formatd',
- llimpl=llimpl, sandboxsafe=True)
-
- @registering(rfloat.parts_to_float)
- def register_parts_to_float(self):
- ll_parts_to_float = self.llexternal('LL_strtod_parts_to_float',
- [rffi.CCHARP] * 4, rffi.DOUBLE,
- sandboxsafe=True,
- threadsafe=False)
-
- def llimpl(sign, beforept, afterpt, exponent):
- res = ll_parts_to_float(sign, beforept, afterpt, exponent)
- if res == -1 and rposix.get_errno() == 42:
- raise ValueError("Wrong literal for float")
- return res
-
- tp = SomeString(can_be_None=True)
- return extdef([tp, tp, tp, tp], float,
- 'll_strtod.ll_strtod_parts_to_float', llimpl=llimpl,
- sandboxsafe=True)
-
-def ensure_decimal_point(s, precision):
- # make sure we have at least one character after the decimal point (and
- # make sure we have a decimal point); also switch to exponential notation
- # in some edge cases where the extra character would produce more
- # significant digits that we really want.
-
- pos = s.find('.')
- if pos >= 0:
- if pos + 1 < len(s) and s[pos + 1].isdigit():
- # Nothing to do, we already have a decimal point
- # and a digit after it
- pass
- else:
- # Normally not used
- s += '0'
- else:
- pos = s.find('e')
- if pos >= 0:
- # Don't add ".0" if we have an exponent
- pass
- else:
- s += '.0'
-
- return s
diff --git a/rpython/rtyper/module/test/test_ll_strtod.py
b/rpython/rtyper/module/test/test_ll_strtod.py
--- a/rpython/rtyper/module/test/test_ll_strtod.py
+++ b/rpython/rtyper/module/test/test_ll_strtod.py
@@ -11,24 +11,3 @@
return rfloat.formatd(y, 'g', 2, flags)
assert self.ll_to_string(self.interpret(f, [3.0])) == f(3.0)
-
- def test_parts_to_float(self):
- from rpython.rtyper.annlowlevel import hlstr
-
- def f(a, b, c, d):
- a,b,c,d = hlstr(a), hlstr(b), hlstr(c), hlstr(d)
-
- return rfloat.parts_to_float(a, b, c, d)
-
- data = [
- (("","1","","") , 1.0),
- (("-","1","","") , -1.0),
- (("-","1","5","") , -1.5),
- (("-","1","5","2") , -1.5e2),
- (("-","1","5","+2") , -1.5e2),
- (("-","1","5","-2") , -1.5e-2),
- ]
-
- for parts, val in data:
- args = [self.string_to_ll(i) for i in parts]
- assert self.interpret(f, args) == val
diff --git a/rpython/rtyper/test/test_rfloat.py
b/rpython/rtyper/test/test_rfloat.py
--- a/rpython/rtyper/test/test_rfloat.py
+++ b/rpython/rtyper/test/test_rfloat.py
@@ -241,21 +241,6 @@
f = compile(func, [float])
assert f(10/3.0) == '3.3333'
- def test_parts_to_float(self):
- from rpython.rlib.rfloat import parts_to_float, break_up_float
- def f(x):
- if x == 0:
- s = '1.0'
- else:
- s = '1e-100'
- sign, beforept, afterpt, expt = break_up_float(s)
- return parts_to_float(sign, beforept, afterpt, expt)
- res = self.interpret(f, [0])
- assert res == 1.0
-
- res = self.interpret(f, [1])
- assert res == 1e-100
-
def test_string_to_float(self):
from rpython.rlib.rfloat import rstring_to_float
def func(x):
diff --git a/rpython/translator/c/test/test_extfunc.py
b/rpython/translator/c/test/test_extfunc.py
--- a/rpython/translator/c/test/test_extfunc.py
+++ b/rpython/translator/c/test/test_extfunc.py
@@ -264,25 +264,6 @@
assert t0 <= res <= t1
-def test_parts_to_float():
- from rpython.rlib.rfloat import parts_to_float
- def fn(sign, beforept, afterpt, exponent):
- return parts_to_float(sign, beforept, afterpt, exponent)
-
- f = compile(fn, [str, str, str, str])
-
- data = [
- (("","1","","") , 1.0),
- (("-","1","","") , -1.0),
- (("-","1","5","") , -1.5),
- (("-","1","5","2") , -1.5e2),
- (("-","1","5","+2") , -1.5e2),
- (("-","1","5","-2") , -1.5e-2),
- ]
-
- for parts, val in data:
- assert f(*parts) == val
-
def test_formatd():
from rpython.rlib.rfloat import formatd
def fn(x):
@@ -453,7 +434,7 @@
f1 = compile(does_stuff, [])
res = f1()
assert res != os.getpid()
-
+
if hasattr(os, 'getpgrp'):
def test_os_getpgrp():
def does_stuff():
diff --git a/rpython/translator/goal/translate.py
b/rpython/translator/goal/translate.py
--- a/rpython/translator/goal/translate.py
+++ b/rpython/translator/goal/translate.py
@@ -19,7 +19,7 @@
from rpython.config.config import (to_optparse, OptionDescription, BoolOption,
ArbitraryOption, StrOption, IntOption, Config, ChoiceOption,
OptHelpFormatter)
from rpython.config.translationoption import (get_combined_translation_config,
- set_opt_level, final_check_config, OPT_LEVELS, DEFAULT_OPT_LEVEL,
set_platform)
+ set_opt_level, OPT_LEVELS, DEFAULT_OPT_LEVEL, set_platform)
GOALS = [
@@ -180,9 +180,6 @@
if 'handle_config' in targetspec_dic:
targetspec_dic['handle_config'](config, translateconfig)
- # perform checks (if any) on the final config
- final_check_config(config)
-
return targetspec_dic, translateconfig, config, args
def show_help(translateconfig, opt_parser, targetspec_dic, config):
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit