[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
- Previous message: [Python-checkins] python/dist/src/Lib/test test_decimal.py, 1.11,
1.12
- Next message: [Python-checkins] python/dist/src/Lib/test/decimaltestdata
decimal128.decTest, NONE, 1.1 decimal32.decTest, NONE,
1.1 abs.decTest, 1.1, 1.2 add.decTest, 1.1, 1.2 base.decTest,
1.1, 1.2 clamp.decTest, 1.1, 1.2 compare.decTest, 1.1,
1.2 decimal64.decTest, 1.1, 1.2 divide.decTest, 1.1,
1.2 divideint.decTest, 1.1, 1.2 inexact.decTest, 1.1,
1.2 max.decTest, 1.1, 1.2 min.decTest, 1.1, 1.2 minus.decTest,
1.1, 1.2 multiply.decTest, 1.1, 1.2 normalize.decTest, 1.1,
1.2 plus.decTest, 1.1, 1.2 power.decTest, 1.1,
1.2 quantize.decTest, 1.1, 1.2 randomBound32.decTest, 1.1,
1.2 randoms.decTest, 1.1, 1.2 remainder.decTest, 1.1,
1.2 remainderNear.decTest, 1.1, 1.2 rescale.decTest, 1.1,
1.2 rounding.decTest, 1.1, 1.2 samequantum.decTest, 1.1,
1.2 squareroot.decTest, 1.1, 1.2 subtract.decTest, 1.1,
1.2 testall.decTest, 1.1, 1.2 tointegral.decTest, 1.1,
1.2 trim.decTest, 1.1, 1.2
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
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)
- Previous message: [Python-checkins] python/dist/src/Lib/test test_decimal.py, 1.11,
1.12
- Next message: [Python-checkins] python/dist/src/Lib/test/decimaltestdata
decimal128.decTest, NONE, 1.1 decimal32.decTest, NONE,
1.1 abs.decTest, 1.1, 1.2 add.decTest, 1.1, 1.2 base.decTest,
1.1, 1.2 clamp.decTest, 1.1, 1.2 compare.decTest, 1.1,
1.2 decimal64.decTest, 1.1, 1.2 divide.decTest, 1.1,
1.2 divideint.decTest, 1.1, 1.2 inexact.decTest, 1.1,
1.2 max.decTest, 1.1, 1.2 min.decTest, 1.1, 1.2 minus.decTest,
1.1, 1.2 multiply.decTest, 1.1, 1.2 normalize.decTest, 1.1,
1.2 plus.decTest, 1.1, 1.2 power.decTest, 1.1,
1.2 quantize.decTest, 1.1, 1.2 randomBound32.decTest, 1.1,
1.2 randoms.decTest, 1.1, 1.2 remainder.decTest, 1.1,
1.2 remainderNear.decTest, 1.1, 1.2 rescale.decTest, 1.1,
1.2 rounding.decTest, 1.1, 1.2 samequantum.decTest, 1.1,
1.2 squareroot.decTest, 1.1, 1.2 subtract.decTest, 1.1,
1.2 testall.decTest, 1.1, 1.2 tointegral.decTest, 1.1,
1.2 trim.decTest, 1.1, 1.2
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the Python-checkins
mailing list