[pypy-commit] pypy py3k: partial backout of 83fc38544bca: we don't want rlib/ to diverge from default
antocuni
noreply at buildbot.pypy.org
Thu Apr 19 15:33:54 CEST 2012
Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: py3k
Changeset: r54533:0000a290ac54
Date: 2012-04-19 14:10 +0200
http://bitbucket.org/pypy/pypy/changeset/0000a290ac54/
Log: partial backout of 83fc38544bca: we don't want rlib/ to diverge from
default
diff --git a/pypy/rlib/rbigint.py b/pypy/rlib/rbigint.py
--- a/pypy/rlib/rbigint.py
+++ b/pypy/rlib/rbigint.py
@@ -285,10 +285,10 @@
def tofloat(self):
return _AsDouble(self)
- def format(self, digits, prefix=''):
+ def format(self, digits, prefix='', suffix=''):
# 'digits' is a string whose length is the base to use,
# and where each character is the corresponding digit.
- return _format(self, digits, prefix)
+ return _format(self, digits, prefix, suffix)
def repr(self):
return _format(self, BASE10, '', 'L')
@@ -601,10 +601,10 @@
if self.sign == 0:
return '0L'
else:
- return _format(self, BASE8, '0')
+ return _format(self, BASE8, '0', 'L')
def hex(self):
- return _format(self, BASE16, '0x')
+ return _format(self, BASE16, '0x', 'L')
def log(self, base):
# base is supposed to be positive or 0.0, which means we use e
@@ -1584,7 +1584,7 @@
BASE10 = '0123456789'
BASE16 = '0123456789abcdef'
-def _format(a, digits, prefix=''):
+def _format(a, digits, prefix='', suffix=''):
"""
Convert a bigint object to a string, using a given conversion base.
Return a string object.
@@ -1600,9 +1600,14 @@
while i > 1:
bits += 1
i >>= 1
- i = 5 + len(prefix) + (size_a*SHIFT + bits-1) // bits
+ i = 5 + len(prefix) + len(suffix) + (size_a*SHIFT + bits-1) // bits
s = [chr(0)] * i
p = i
+ j = len(suffix)
+ while j > 0:
+ p -= 1
+ j -= 1
+ s[p] = suffix[j]
if a.sign == 0:
p -= 1
More information about the pypy-commit
mailing list