File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -365,6 +365,29 @@ Decimal objects
365365 compared, sorted, and coerced to another type (such as :class: `float ` or
366366 :class: `int `).
367367
368+ There are some small differences between arithmetic on Decimal objects and
369+ arithmetic on integers and floats. When the remainder operator ``% `` is
370+ applied to Decimal objects, the sign of the result is the sign of the
371+ *dividend * rather than the sign of the divisor::
372+
373+ >>> (-7) % 4
374+ 1
375+ >>> Decimal(-7) % Decimal(4)
376+ Decimal('-3')
377+
378+ The integer division operator ``// `` behaves analogously, returning the
379+ integer part of the true quotient (truncating towards zero) rather than its
380+ floor, so as to preseve the usual identity ``x == (x // y) * y + x % y ``::
381+
382+ >>> -7 // 4
383+ -2
384+ >>> Decimal(-7) // Decimal(4)
385+ Decimal('-1')
386+
387+ The ``% `` and ``// `` operators implement the ``remainder `` and
388+ ``divide-integer `` operations (respectively) as described in the
389+ specification.
390+
368391 Decimal objects cannot generally be combined with floats or
369392 instances of :class: `fractions.Fraction ` in arithmetic operations:
370393 an attempt to add a :class: `Decimal ` to a :class: `float `, for
You can’t perform that action at this time.
0 commit comments