Index: Misc/NEWS =================================================================== --- Misc/NEWS (revision 75186) +++ Misc/NEWS (working copy) @@ -390,6 +390,9 @@ Library ------- +- Issue #7049: Slightly relax restrictions on 3-argument pow for Decimal: + the modulus is now only required to be <= 10**prec, not < 10**prec. + - Issue #7031: Add TestCase.assert(Not)IsInstance() methods. - Issue #6790: Make it possible again to pass an `array.array` to Index: Doc/library/decimal.rst =================================================================== --- Doc/library/decimal.rst (revision 75186) +++ Doc/library/decimal.rst (working copy) @@ -1316,7 +1316,8 @@ - all three arguments must be integral - ``y`` must be nonnegative - at least one of ``x`` or ``y`` must be nonzero - - ``modulo`` must be nonzero and have at most 'precision' digits + - ``modulo`` must be nonzero, and at most ``10**precision`` in + absolute value. The result of ``Context.power(x, y, modulo)`` is identical to the result that would be obtained by computing ``(x**y) % modulo`` with unbounded Index: Lib/decimal.py =================================================================== --- Lib/decimal.py (revision 75186) +++ Lib/decimal.py (working copy) @@ -1845,13 +1845,13 @@ return context._raise_error(InvalidOperation, 'pow() 3rd argument cannot be 0') - # additional restriction for decimal: the modulus must be less - # than 10**prec in absolute value - if modulo.adjusted() >= context.prec: + # additional restriction for decimal: the modulus must be at + # most 10**prec in absolute value + if modulo.copy_abs() > _dec_from_triple(0, '1', context.prec): return context._raise_error(InvalidOperation, 'insufficient precision: pow() 3rd ' - 'argument must not have more than ' - 'precision digits') + 'argument must be at most ' + '10**precision') # define 0**0 == NaN, for consistency with two-argument pow # (even though it hurts!) Index: Lib/test/decimaltestdata/extra.decTest =================================================================== --- Lib/test/decimaltestdata/extra.decTest (revision 75186) +++ Lib/test/decimaltestdata/extra.decTest (working copy) @@ -2651,8 +2651,8 @@ -- Modulus must not exceed precision pwmx325 power 0 1 1234567890 -> NaN Invalid_operation -pwmx326 power 1 0 1000000000 -> NaN Invalid_operation -pwmx327 power -23 5 -1000000000 -> NaN Invalid_operation +pwmx326 power 1 0 1000000000 -> 1 +pwmx327 power -23 5 -1000000000 -> -6436343 pwmx328 power 41557 213 -999999999 -> 47650456 pwmx329 power -2134 199 999999997 -> -946957912 @@ -2704,3 +2704,13 @@ pwmx438 power 18 1728 1729 -> 1 pwmx439 power 19 1728 1729 -> 456 pwmx440 power 20 1728 1729 -> 1 + +-- More modulus and precision checks: in Python 2.7, +-- the modulus is allowed to be up to 10**precision; +-- previously its max value was 10**precision-1. +pwmx500 power 0 0 1000000001 -> NaN Invalid_operation +pwmx501 power 1 0 1000000001 -> NaN Invalid_operation +pwmx502 power 1 1 1000000001 -> NaN Invalid_operation +pwmx503 power 0 1 1000000001 -> NaN Invalid_operation +pwmx504 power 1e15 5176 1000000001 -> NaN Invalid_operation +pwmx504 power 12 132 -1000000001 -> NaN Invalid_operation