Skip to content
Merged
Prev Previous commit
Next Next commit
Clarify that the negative third argument only applies for int type op…
…erands.
  • Loading branch information
mdickinson committed Jun 1, 2019
commit fca728e26b9cf72c29ea694b588517546ad051a1
13 changes: 7 additions & 6 deletions Doc/library/functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1261,14 +1261,15 @@ are always available. They are listed here in alphabetical order.
converted to float and a float result is delivered. For example, ``10**2``
returns ``100``, but ``10**-2`` returns ``0.01``.

If *z* is present, all three of *x*, *y* and *z* must be of integer type
and *z* must be nonzero. If *z* is present and *y* is negative, *x* must
be relatively prime to *z*. In that case, ``pow(ix, -y, z)`` is returned,
where *ix* is an inverse to *x* modulo *z*.
For :class:`int` operands *x* and *y*, if *z* is present, *z* must also be
of integer type and *z* must be nonzero. If *z* is present and *y* is
negative, *x* must be relatively prime to *z*. In that case, ``pow(ix, -y,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider changing ix to inv_x for readability.

z)`` is returned, where *ix* is an inverse to *x* modulo *z*.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps this needs an example for clarity:

# Multiplicative inverse of 38 in mod 97
>>> pow(38, -1, 97)
23
>>> 23 * 38 % 97 == 1
True


.. versionchanged:: 3.8
The three-argument form now allows the second argument to be negative,
permitting computation of modular inverses.
For :class:`int` operands, the three-argument form of ``pow`` now allows
the second argument to be negative, permitting computation of modular
inverses.


.. function:: print(*objects, sep=' ', end='\\n', file=sys.stdout, flush=False)
Expand Down