[pypy-svn] pypy shorter-float-repr: One function for them to call and to shorter repr bring them.
amauryfa
commits-noreply at bitbucket.org
Fri Jan 21 17:28:23 CET 2011
Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: shorter-float-repr
Changeset: r41154:6d1dca2a0356
Date: 2011-01-21 17:23 +0100
http://bitbucket.org/pypy/pypy/changeset/6d1dca2a0356/
Log: One function for them to call and to shorter repr bring them.
diff --git a/pypy/rlib/rarithmetic.py b/pypy/rlib/rarithmetic.py
--- a/pypy/rlib/rarithmetic.py
+++ b/pypy/rlib/rarithmetic.py
@@ -517,8 +517,15 @@
r_int64 = int
+def string_to_float(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)
+
# float as string -> sign, beforept, afterpt, exponent
-
def break_up_float(s):
i = 0
diff --git a/pypy/rlib/rmarshal.py b/pypy/rlib/rmarshal.py
--- a/pypy/rlib/rmarshal.py
+++ b/pypy/rlib/rmarshal.py
@@ -7,7 +7,7 @@
from pypy.annotation.listdef import ListDef, TooLateForChange
from pypy.tool.pairtype import pair, pairtype
from pypy.rlib.rarithmetic import formatd, r_longlong, intmask, LONG_BIT
-from pypy.rlib.rarithmetic import break_up_float, parts_to_float
+from pypy.rlib.rarithmetic import string_to_float
from pypy.rlib.unroll import unrolling_iterable
class CannotMarshal(Exception):
@@ -205,7 +205,7 @@
raise ValueError("expected a float")
length = ord(readchr(loader))
s = readstr(loader, length)
- return parts_to_float(*break_up_float(s))
+ return string_to_float(s)
add_loader(annmodel.SomeFloat(), load_float)
def dump_string_or_none(buf, x):
diff --git a/pypy/objspace/std/strutil.py b/pypy/objspace/std/strutil.py
--- a/pypy/objspace/std/strutil.py
+++ b/pypy/objspace/std/strutil.py
@@ -2,8 +2,7 @@
Pure Python implementation of string utilities.
"""
-from pypy.rlib.rarithmetic import ovfcheck, break_up_float, parts_to_float,\
- INFINITY, NAN
+from pypy.rlib.rarithmetic import ovfcheck, string_to_float, INFINITY, NAN
from pypy.rlib.rbigint import rbigint, parse_digit_string
from pypy.interpreter.error import OperationError
import math
@@ -179,14 +178,7 @@
elif low == "nan" or low == "-nan" or low == "+nan":
return NAN
- # 1) parse the string into pieces.
try:
- sign, before_point, after_point, exponent = break_up_float(s)
+ return string_to_float(s)
except ValueError:
raise ParseStringError("invalid literal for float()")
-
- digits = before_point + after_point
- if not digits:
- raise ParseStringError("invalid literal for float()")
-
- return parts_to_float(sign, before_point, after_point, exponent)
diff --git a/pypy/rpython/rstr.py b/pypy/rpython/rstr.py
--- a/pypy/rpython/rstr.py
+++ b/pypy/rpython/rstr.py
@@ -712,7 +712,7 @@
def ll_float(ll_str):
from pypy.rpython.annlowlevel import hlstr
- from pypy.rlib.rarithmetic import break_up_float, parts_to_float
+ from pypy.rlib.rarithmetic import string_to_float
s = hlstr(ll_str)
assert s is not None
@@ -732,12 +732,7 @@
else:
break
assert end >= 0
- sign, before_point, after_point, exponent = break_up_float(s[beg:end+1])
-
- if not before_point and not after_point:
- raise ValueError
-
- return parts_to_float(sign, before_point, after_point, exponent)
+ return string_to_float(s[beg:end+1])
def ll_splitlines(cls, LIST, ll_str, keep_newlines):
from pypy.rpython.annlowlevel import hlstr
More information about the Pypy-commit
mailing list