[Python-checkins] python/dist/src/Lib decimal.py,1.21,1.22

rhettinger at users.sourceforge.net rhettinger at users.sourceforge.net
Tue Aug 17 08:39:50 CEST 2004


Update of /cvsroot/python/python/dist/src/Lib
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19307

Modified Files:
	decimal.py 
Log Message:
Revise max() and min() to comply with the 8/2/2004 update to the specification
(version 1.45):

The max and min operations follow the rules in the current IEEE 754 revision draft: 
if one operand is a quiet NaN and the other is number, then the number is always returned 
if both operands are finite and equal in numerical value then an ordering is applied:
    if the signs differ then max returns the operand with the positive sign and
    min returns the operand with the negative sign; if the signs are the same then
    the exponent is used to select the result.



Index: decimal.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/decimal.py,v
retrieving revision 1.21
retrieving revision 1.22
diff -C2 -d -r1.21 -r1.22
*** decimal.py	8 Aug 2004 04:03:24 -0000	1.21
--- decimal.py	17 Aug 2004 06:39:37 -0000	1.22
***************
*** 2033,2047 ****
          other = self._convert_other(other)
  
!         ans = self._check_nans(other, context)
!         if ans:
!             return ans
  
          ans = self
!         if self < other:
              ans = other
!         shouldround = context._rounding_decision == ALWAYS_ROUND
!         if shouldround:
!             ans = ans._fix(context=context)
!         return ans
  
      def min(self, other, context=None):
--- 2033,2069 ----
          other = self._convert_other(other)
  
!         # if one operand is a quiet NaN and the other is number, then the
!         # number is always returned
!         sn = self._isnan()
!         on = other._isnan()
!         if sn or on:
!             if on == 1 and sn != 2:
!                 return self
!             if sn == 1 and on != 2:
!                 return other
!             return self._check_nans(other, context)
  
          ans = self
!         c = self.__cmp__(other)
!         if c == 0:
!             # if both operands are finite and equal in numerical value
!             # then an ordering is applied:
!             #
!             # if the signs differ then max returns the operand with the
!             # positive sign and min returns the operand with the negative sign
!             #
!             # if the signs are the same then the exponent is used to select
!             # the result.
!             if self._sign != other._sign:
!                 if self._sign:
!                     ans = other
!             elif self._exp < other._exp and not self._sign:
!                 ans = other
!             elif self._exp > other._exp and self._sign:
!                 ans = other
!         elif c == -1:
              ans = other
!         context._rounding_decision == ALWAYS_ROUND
!         return ans._fix(context=context)
  
      def min(self, other, context=None):
***************
*** 2055,2071 ****
          other = self._convert_other(other)
  
!         ans = self._check_nans(other, context)
!         if ans:
!             return ans
  
          ans = self
! 
!         if self > other:
              ans = other
! 
!         if context._rounding_decision == ALWAYS_ROUND:
!             ans = ans._fix(context=context)
! 
!         return ans
  
      def _isinteger(self):
--- 2077,2113 ----
          other = self._convert_other(other)
  
!         # if one operand is a quiet NaN and the other is number, then the
!         # number is always returned
!         sn = self._isnan()
!         on = other._isnan()
!         if sn or on:
!             if on == 1 and sn != 2:
!                 return self
!             if sn == 1 and on != 2:
!                 return other
!             return self._check_nans(other, context)
  
          ans = self
!         c = self.__cmp__(other)
!         if c == 0:
!             # if both operands are finite and equal in numerical value
!             # then an ordering is applied:
!             #
!             # if the signs differ then max returns the operand with the
!             # positive sign and min returns the operand with the negative sign
!             #
!             # if the signs are the same then the exponent is used to select
!             # the result.
!             if self._sign != other._sign:
!                 if other._sign:
!                     ans = other
!             elif self._exp > other._exp and not self._sign:
!                 ans = other
!             elif self._exp < other._exp and self._sign:
!                 ans = other
!         elif c == 1:
              ans = other
!         context._rounding_decision == ALWAYS_ROUND
!         return ans._fix(context=context)
  
      def _isinteger(self):
***************
*** 2398,2402 ****
          Decimal("3")
          >>> ExtendedContext.max(Decimal('1.0'), Decimal('1'))
!         Decimal("1.0")
          """
          return a.max(b, context=self)
--- 2440,2446 ----
          Decimal("3")
          >>> ExtendedContext.max(Decimal('1.0'), Decimal('1'))
!         Decimal("1")
!         >>> ExtendedContext.max(Decimal('7'), Decimal('NaN'))
!         Decimal("7")
          """
          return a.max(b, context=self)
***************
*** 2417,2420 ****
--- 2461,2466 ----
          >>> ExtendedContext.min(Decimal('1.0'), Decimal('1'))
          Decimal("1.0")
+         >>> ExtendedContext.min(Decimal('7'), Decimal('NaN'))
+         Decimal("7")
          """
          return a.min(b, context=self)



More information about the Python-checkins mailing list