[Python-checkins] python/nondist/sandbox/decimal Decimal.py, 1.27,
1.28 test_Decimal.py, 1.22, 1.23
rhettinger at users.sourceforge.net
rhettinger at users.sourceforge.net
Wed Jun 30 00:22:56 EDT 2004
Update of /cvsroot/python/python/nondist/sandbox/decimal
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28773
Modified Files:
Decimal.py test_Decimal.py
Log Message:
The decimal constructor for integer arguments now converts integer
input to a string and then applies the usual "to-number" rules.
* restores the domain to include all possible integer inputs
between the under and overflow limits
* Makes sure that Decimal(12345)==Decimal('12345') even when the precision
is only three.
* Makes sure that integer handling honors the spirit of the to-number rules.
Index: Decimal.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/decimal/Decimal.py,v
retrieving revision 1.27
retrieving revision 1.28
diff -C2 -d -r1.27 -r1.28
*** Decimal.py 30 Jun 2004 01:06:02 -0000 1.27
--- Decimal.py 30 Jun 2004 04:22:54 -0000 1.28
***************
*** 399,402 ****
--- 399,405 ----
context = getcontext()
+ if isinstance(value, (int,long)):
+ value = str(value)
+
# String?
# REs insist on real strings, so we can too.
***************
*** 427,440 ****
return
- ### XXX Hmm, with precision=3, Decimal(12345) fails with Decimal('12345') works
- if isinstance(value, (int,long)):
- # checking that the int or long doesn't exceed precision
- max_int = 10 ** context.prec
- if value > max_int:
- raise ValueError, "Exceeded precision: use a smaller int or a Decimal with more precision"
- # converting it
- self._convertString(str(value), context)
- return
-
# tuple/list conversion (possibly from as_tuple())
if isinstance(value, (list,tuple)):
--- 430,433 ----
Index: test_Decimal.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/decimal/test_Decimal.py,v
retrieving revision 1.22
retrieving revision 1.23
diff -C2 -d -r1.22 -r1.23
*** test_Decimal.py 30 Jun 2004 01:06:02 -0000 1.22
--- test_Decimal.py 30 Jun 2004 04:22:54 -0000 1.23
***************
*** 191,195 ****
conglomerate = ''
quote = 0
! theirexceptions = map(lambda x: ErrorNames[x.lower()], exceptions)
for exception in ExceptionList:
--- 191,195 ----
conglomerate = ''
quote = 0
! theirexceptions = [ErrorNames[x.lower()] for x in exceptions]
for exception in ExceptionList:
***************
*** 490,494 ****
d = nc.create_decimal(456)
self.failUnless(isinstance(d, Decimal))
! self.assertRaises(ValueError, nc.create_decimal, 45678)
# from string
--- 490,495 ----
d = nc.create_decimal(456)
self.failUnless(isinstance(d, Decimal))
! self.assertEqual(nc.create_decimal(45678),
! nc.create_decimal('457E+2'))
# from string
***************
*** 527,531 ****
#exceeding precision
! self.assertRaises(ValueError, eval, 'Decimal(5) + 123456789000', globals())
def test_from_string(self):
--- 528,532 ----
#exceeding precision
! self.assertEqual(Decimal(5) + 123456789000, Decimal(123456789000))
def test_from_string(self):
More information about the Python-checkins
mailing list