diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2020-02-23 11:21:29 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-23 11:21:29 (GMT) |
commit | 559e7f165ad03731e6bc2211c0e6d8d9c02fb549 (patch) | |
tree | 0cf0f31bae98ea188a5fde21a1db4c068539dbdb /Doc/library | |
parent | fbe2e0bb8a7ee75d0f9d57682436dac7d69e202e (diff) | |
download | cpython-559e7f165ad03731e6bc2211c0e6d8d9c02fb549.zip cpython-559e7f165ad03731e6bc2211c0e6d8d9c02fb549.tar.gz cpython-559e7f165ad03731e6bc2211c0e6d8d9c02fb549.tar.bz2 |
bpo-39648: Expand math.gcd() and math.lcm() to handle multiple arguments. (GH-18604)
* bpo-39648: Expand math.gcd() and math.lcm() to handle multiple arguments.
* Simplify fast path.
* Difine lcm() without arguments returning 1.
* Apply suggestions from code review
Co-Authored-By: Mark Dickinson <dickinsm@gmail.com>
Co-authored-by: Mark Dickinson <dickinsm@gmail.com>
Diffstat (limited to 'Doc/library')
-rw-r--r-- | Doc/library/math.rst | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/Doc/library/math.rst b/Doc/library/math.rst index d8ac352..6ec1fee 100644 --- a/Doc/library/math.rst +++ b/Doc/library/math.rst @@ -126,23 +126,19 @@ Number-theoretic and representation functions <https://code.activestate.com/recipes/393090/>`_\. -.. function:: gcd(a, b) +.. function:: gcd(*integers) - Return the greatest common divisor of the integers *a* and *b*. If either - *a* or *b* is nonzero, then the value of ``gcd(a, b)`` is the largest - positive integer that divides both *a* and *b*. ``gcd(0, 0)`` returns - ``0``. + Return the greatest common divisor of the specified integer arguments. + If any of the arguments is nonzero, then the returned value is the largest + positive integer that is a divisor af all arguments. If all arguments + are zero, then the returned value is ``0``. ``gcd()`` without arguments + returns ``0``. .. versionadded:: 3.5 - -.. function:: lcm(a, b) - - Return the least common multiple of integers *a* and *b*. The value of - ``lcm(a, b)`` is the smallest nonnegative integer that is a multiple of - both *a* and *b*. If either *a* or *b* is zero then ``lcm(a, b)`` is zero. - - .. versionadded:: 3.9 + .. versionchanged:: 3.9 + Added support for an arbitrary number of arguments. Formerly, only two + arguments were supported. .. function:: isclose(a, b, *, rel_tol=1e-09, abs_tol=0.0) @@ -210,6 +206,17 @@ Number-theoretic and representation functions .. versionadded:: 3.8 +.. function:: lcm(*integers) + + Return the least common multiple of the specified integer arguments. + If all arguments are nonzero, then the returned value is the smallest + positive integer that is a multiple of all arguments. If any of the arguments + is zero, then the returned value is ``0``. ``lcm()`` without arguments + returns ``1``. + + .. versionadded:: 3.9 + + .. function:: ldexp(x, i) Return ``x * (2**i)``. This is essentially the inverse of function |