[Python-checkins] python/nondist/sandbox/decimal Decimal.py, 1.11, 1.12 test_Decimal.py, 1.2, 1.3

eprice at users.sourceforge.net eprice at users.sourceforge.net
Tue Aug 12 17:04:26 EDT 2003


Update of /cvsroot/python/python/nondist/sandbox/decimal
In directory sc8-pr-cvs1:/tmp/cvs-serv7049

Modified Files:
	Decimal.py test_Decimal.py 
Log Message:
Updated to add tointegral function and  unittest.



Index: Decimal.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/decimal/Decimal.py,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** Decimal.py	4 Jul 2003 03:11:42 -0000	1.11
--- Decimal.py	12 Aug 2003 23:04:23 -0000	1.12
***************
*** 1644,1647 ****
--- 1644,1648 ----
              context = getcontext()
  
+         #Because the spot << doesn't work with really big exponents
          if n._isinfinity() or n.adjusted() > 8:
              return context.raise_error(InvalidOperation, 'x ** INF')
***************
*** 1687,1691 ****
          firstprec = context.prec
  
!         if firstprec + elength + 1 > ABSOLUTE_MAX_EXP:
              return context.raise_error(Overflow, 'Too much precision.', sign)
  
--- 1688,1692 ----
          firstprec = context.prec
  
!         if not modulo and firstprec + elength + 1 > ABSOLUTE_MAX_EXP:
              return context.raise_error(Overflow, 'Too much precision.', sign)
  
***************
*** 1824,1827 ****
--- 1825,1842 ----
          return self.rescale(0, rounding, context=context)
  
+     def tointegral(self, rounding = None, context=None):
+         """Rounds to the nearest integer, without raising inexact, rounded."""
+         if context is None:
+             context = getcontext()
+         ans = self._check_nans(context=context)
+         if ans:
+             return ans
+         if self._exp >= 0:
+             return self
+         flags = context.ignore_flags(Rounded, Inexact)
+         ans = self.rescale(0, rounding, context=context)
+         context.regard_flags(flags)
+         return ans
+ 
      def sqrt(self, context=None):
          """Return the square root of self.
***************
*** 2232,2235 ****
--- 2247,2252 ----
      def tosci(self, a):
          return a.sci(context=self)
+     def tointegral(self, a):
+         return a.tointegral(context=self)
      def trim(self, a):
          return a.trim(context=self)

Index: test_Decimal.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/decimal/test_Decimal.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** test_Decimal.py	2 Jul 2003 23:50:01 -0000	1.2
--- test_Decimal.py	12 Aug 2003 23:04:23 -0000	1.3
***************
*** 268,277 ****
          self.eval_file(dir + 'inexact' + '.decTest')
  
!     def test_integer(self):
!         """Tests the Decimal class on Cowlishaw's integer tests.
! 
!         See www2.hursley.ibm.com/decimal/decTest.zip to download the suite.
!         """
!         self.eval_file(dir + 'integer' + '.decTest')
  
      def test_max(self):
--- 268,277 ----
          self.eval_file(dir + 'inexact' + '.decTest')
  
!     #def test_integer(self):
!     #    """Tests the Decimal class on Cowlishaw's integer tests.
!     #
!     #    See www2.hursley.ibm.com/decimal/decTest.zip to download the suite.
!     #    """
!     #    self.eval_file(dir + 'integer' + '.decTest')
  
      def test_max(self):
***************
*** 379,382 ****
--- 379,389 ----
          """
          self.eval_file(dir + 'subtract' + '.decTest')
+ 
+     def test_tointegral(self):
+         """Tests the Decimal class on Cowlishaw's tointegral tests.
+ 
+         See www2.hursley.ibm.com/decimal/decTest.zip to download the suite.
+         """
+         self.eval_file(dir + 'tointegral' + '.decTest')
  
      def test_trim(self):





More information about the Python-checkins mailing list