summaryrefslogtreecommitdiff
path: root/Doc/library/decimal.rst
diff options
context:
space:
mode:
authorMark Dickinson <dickinsm@gmail.com>2010-04-03 11:08:14 +0000
committerMark Dickinson <dickinsm@gmail.com>2010-04-03 11:08:14 +0000
commitac256ab2843dfb6c28af0227202df67664ed462e (patch)
treee4b82bd27da37911a04fde01cc06e7ddc39681df /Doc/library/decimal.rst
parent5fc16b469ea96f1db11bb2fc9996ac056e8e1c3c (diff)
downloadcpython-git-ac256ab2843dfb6c28af0227202df67664ed462e.tar.gz
Merged revisions 79583,79588-79589 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r79583 | mark.dickinson | 2010-04-02 09:53:22 +0100 (Fri, 02 Apr 2010) | 7 lines Issue #2531: Make float-to-decimal comparisons return correct results. Float to decimal comparison operations now return a result based on the numeric values of the operands. Decimal.__hash__ has also been fixed so that Decimal and float values that compare equal have equal hash value. ........ r79588 | mark.dickinson | 2010-04-02 11:17:07 +0100 (Fri, 02 Apr 2010) | 2 lines Issue #7279: Make comparisons involving a Decimal sNaN signal InvalidOperation. ........ r79589 | mark.dickinson | 2010-04-02 11:35:12 +0100 (Fri, 02 Apr 2010) | 6 lines Issue #7279: Make Decimal('nan') hashable. Decimal('snan') remains unhashable. Also rewrite the Decimal __hash__ method so that it doesn't rely on float('inf') being valid: float('inf') could raise an exception on platforms not using IEEE 754 arithmetic. ........
Diffstat (limited to 'Doc/library/decimal.rst')
-rw-r--r--Doc/library/decimal.rst18
1 files changed, 18 insertions, 0 deletions
diff --git a/Doc/library/decimal.rst b/Doc/library/decimal.rst
index 9d6ad81eb5..8a806e97c4 100644
--- a/Doc/library/decimal.rst
+++ b/Doc/library/decimal.rst
@@ -358,6 +358,24 @@ Decimal objects
compared, sorted, and coerced to another type (such as :class:`float` or
:class:`int`).
+ Decimal objects cannot generally be combined with floats in
+ arithmetic operations: an attempt to add a :class:`Decimal` to a
+ :class:`float`, for example, will raise a :exc:`TypeError`.
+ There's one exception to this rule: it's possible to use Python's
+ comparison operators to compare a :class:`float` instance ``x``
+ with a :class:`Decimal` instance ``y``. Without this exception,
+ comparisons between :class:`Decimal` and :class:`float` instances
+ would follow the general rules for comparing objects of different
+ types described in the :ref:`expressions` section of the reference
+ manual, leading to confusing results.
+
+ .. versionchanged:: 2.7
+ A comparison between a :class:`float` instance ``x`` and a
+ :class:`Decimal` instance ``y`` now returns a result based on
+ the values of ``x`` and ``y``. In earlier versions ``x < y``
+ returned the same (arbitrary) result for any :class:`Decimal`
+ instance ``x`` and any :class:`float` instance ``y``.
+
In addition to the standard numeric properties, decimal floating point
objects also have a number of specialized methods: