[pypy-svn] r42008 - in pypy/dist/pypy: module/__builtin__ rlib
fijal at codespeak.net
fijal at codespeak.net
Thu Apr 12 21:44:25 CEST 2007
Author: fijal
Date: Thu Apr 12 21:44:24 2007
New Revision: 42008
Modified:
pypy/dist/pypy/module/__builtin__/special.py
pypy/dist/pypy/rlib/rarithmetic.py
Log:
Move overflow checking version of formatd from __builtin__.special
to rlib, to reuse by formatting
Modified: pypy/dist/pypy/module/__builtin__/special.py
==============================================================================
--- pypy/dist/pypy/module/__builtin__/special.py (original)
+++ pypy/dist/pypy/module/__builtin__/special.py Thu Apr 12 21:44:24 2007
@@ -3,19 +3,11 @@
from pypy.rlib import rarithmetic
def _formatd(space, alt, prec, kind, x):
- formatd_max_length = rarithmetic.formatd_max_length
- if ((kind == 'g' and formatd_max_length <= 10+prec) or
- (kind == 'f' and formatd_max_length <= 53+prec)):
- raise OperationError(space.w_OverflowError,
- space.wrap("formatted float is too long (precision too large?)"))
- if alt:
- alt = '#'
- else:
- alt = ''
-
- fmt = "%%%s.%d%s" % (alt, prec, kind)
-
- return space.wrap(rarithmetic.formatd(fmt, x))
+ try:
+ return space.wrap(rarithmetic.formatd_overflow(alt, prec, kind, x))
+ except OverflowError:
+ raise OperationError(space.w_OverflowError, space.wrap(
+ "formatted float is too long (precision too large?)"))
_formatd.unwrap_spec = [gateway.ObjSpace, int, int, str, float]
Modified: pypy/dist/pypy/rlib/rarithmetic.py
==============================================================================
--- pypy/dist/pypy/rlib/rarithmetic.py (original)
+++ pypy/dist/pypy/rlib/rarithmetic.py Thu Apr 12 21:44:24 2007
@@ -409,6 +409,19 @@
def formatd(fmt, x):
return fmt % (x,)
+def formatd_overflow(alt, prec, kind, x):
+ if ((kind == 'g' and formatd_max_length <= 10+prec) or
+ (kind == 'f' and formatd_max_length <= 53+prec)):
+ raise OverflowError("formatted float is too long (precision too large?)")
+ if alt:
+ alt = '#'
+ else:
+ alt = ''
+
+ fmt = "%%%s.%d%s" % (alt, prec, kind)
+
+ return formatd(fmt, x)
+
# a common string hash function
def _hash_string(s):
More information about the pypy-svn
mailing list