[Python-checkins] python/nondist/sandbox/decimal Decimal.py, 1.16, 1.17

facundobatista at users.sourceforge.net facundobatista at users.sourceforge.net
Sun Apr 4 00:00:17 EST 2004


Update of /cvsroot/python/python/nondist/sandbox/decimal
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16235

Modified Files:
	Decimal.py 
Log Message:
Finished from_float method.

Index: Decimal.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/decimal/Decimal.py,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -d -r1.16 -r1.17
*** Decimal.py	3 Apr 2004 02:15:21 -0000	1.16
--- Decimal.py	4 Apr 2004 05:00:13 -0000	1.17
***************
*** 440,443 ****
--- 440,448 ----
  
          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
***************
*** 499,503 ****
                  raise TypeError, "positions must be not negative in Decimal.from_float(value, [positions])"
  #            d = d.fix(positions)
!             d = d.round(positions, ROUND_HALF_UP)
              
          return d
--- 504,512 ----
                  raise TypeError, "positions must be not negative in Decimal.from_float(value, [positions])"
  #            d = d.fix(positions)
! 
!             # we must know what precision to pass to round
!             int_positions = len(d._int) + d._exp
!             real_decimal_positions = positions + int_positions
!             d = d.round(real_decimal_positions, ROUND_HALF_UP)
              
          return d




More information about the Python-checkins mailing list