summaryrefslogtreecommitdiff
path: root/Lib/decimal.py
diff options
context:
space:
mode:
authorMark Dickinson <dickinsm@gmail.com>2010-04-02 10:17:07 +0000
committerMark Dickinson <dickinsm@gmail.com>2010-04-02 10:17:07 +0000
commite096e82e827f6092706c7349fd4944c275382eb5 (patch)
tree9d9f8a1f53574d56a605499484d44508c252ef62 /Lib/decimal.py
parentea2d38947461039b49ff2f04d28bf14bf92194df (diff)
downloadcpython-git-e096e82e827f6092706c7349fd4944c275382eb5.tar.gz
Issue #7279: Make comparisons involving a Decimal sNaN signal InvalidOperation.
Diffstat (limited to 'Lib/decimal.py')
-rw-r--r--Lib/decimal.py15
1 files changed, 9 insertions, 6 deletions
diff --git a/Lib/decimal.py b/Lib/decimal.py
index 159669c3f3..52ac7a8b8b 100644
--- a/Lib/decimal.py
+++ b/Lib/decimal.py
@@ -845,8 +845,11 @@ class Decimal(object):
# subject of what should happen for a comparison involving a NaN.
# We take the following approach:
#
- # == comparisons involving a NaN always return False
- # != comparisons involving a NaN always return True
+ # == comparisons involving a quiet NaN always return False
+ # != comparisons involving a quiet NaN always return True
+ # == or != comparisons involving a signaling NaN signal
+ # InvalidOperation, and return False or True as above if the
+ # InvalidOperation is not trapped.
# <, >, <= and >= comparisons involving a (quiet or signaling)
# NaN signal InvalidOperation, and return False if the
# InvalidOperation is not trapped.
@@ -854,19 +857,19 @@ class Decimal(object):
# This behavior is designed to conform as closely as possible to
# that specified by IEEE 754.
- def __eq__(self, other):
+ def __eq__(self, other, context=None):
other = _convert_other(other, allow_float=True)
if other is NotImplemented:
return other
- if self.is_nan() or other.is_nan():
+ if self._check_nans(other, context):
return False
return self._cmp(other) == 0
- def __ne__(self, other):
+ def __ne__(self, other, context=None):
other = _convert_other(other, allow_float=True)
if other is NotImplemented:
return other
- if self.is_nan() or other.is_nan():
+ if self._check_nans(other, context):
return True
return self._cmp(other) != 0