diff options
author | Mark Dickinson <mdickinson@enthought.com> | 2012-11-18 10:22:40 +0000 |
---|---|---|
committer | Mark Dickinson <mdickinson@enthought.com> | 2012-11-18 10:22:40 +0000 |
commit | f56c361212ccf3bb63c7b3e1b8e3517983890612 (patch) | |
tree | 9fe8b610c0f67f115a2806caebe69413ca141348 /Doc/library/decimal.rst | |
parent | 8572da5e961f6a645e3e8932568afd889448e78b (diff) | |
parent | a3f37408da2be22e2294c4bc14d23a66bb7c5570 (diff) | |
download | cpython-git-f56c361212ccf3bb63c7b3e1b8e3517983890612.tar.gz |
Issue #12005: merge doc patch from 3.2
Diffstat (limited to 'Doc/library/decimal.rst')
-rw-r--r-- | Doc/library/decimal.rst | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/Doc/library/decimal.rst b/Doc/library/decimal.rst index 1fc56ad10f..aa9b1e322e 100644 --- a/Doc/library/decimal.rst +++ b/Doc/library/decimal.rst @@ -400,6 +400,29 @@ Decimal objects compared, sorted, and coerced to another type (such as :class:`float` or :class:`int`). + There are some small differences between arithmetic on Decimal objects and + arithmetic on integers and floats. When the remainder operator ``%`` is + applied to Decimal objects, the sign of the result is the sign of the + *dividend* rather than the sign of the divisor:: + + >>> (-7) % 4 + 1 + >>> Decimal(-7) % Decimal(4) + Decimal('-3') + + The integer division operator ``//`` behaves analogously, returning the + integer part of the true quotient (truncating towards zero) rather than its + floor, so as to preseve the usual identity ``x == (x // y) * y + x % y``:: + + >>> -7 // 4 + -2 + >>> Decimal(-7) // Decimal(4) + Decimal('-1') + + The ``%`` and ``//`` operators implement the ``remainder`` and + ``divide-integer`` operations (respectively) as described in the + specification. + Decimal objects cannot generally be combined with floats or instances of :class:`fractions.Fraction` in arithmetic operations: an attempt to add a :class:`Decimal` to a :class:`float`, for |