]> Cypherpunks repositories - gostls13.git/commit
math/big: allow all values for GCD
authorBrian Kessler <brian.m.kessler@gmail.com>
Wed, 13 Feb 2019 05:21:42 +0000 (22:21 -0700)
committerRobert Griesemer <gri@golang.org>
Thu, 7 Nov 2019 06:58:44 +0000 (06:58 +0000)
commitf5949b60676bc253aca36fea91f9542e6d517f9e
tree4ad93767b0a8574fc8ae016514c35de197d7b655
parenta8f57f4adad2122b42ea05024b61e93442788289
math/big: allow all values for GCD

Allow the inputs a and b to be zero or negative to GCD
with the following definitions.

If x or y are not nil, GCD sets their value such that z = a*x + b*y.
Regardless of the signs of a and b, z is always >= 0.
If a == b == 0, GCD sets z = x = y = 0.
If a == 0 and b != 0, GCD sets z = |b|, x = 0, y = sign(b) * 1.
If a != 0 and b == 0, GCD sets z = |a|, x = sign(a) * 1, y = 0.

Fixes #28878

Change-Id: Ia83fce66912a96545c95cd8df0549bfd852652f3
Reviewed-on: https://go-review.googlesource.com/c/go/+/164972
Run-TryBot: Brian Kessler <brian.m.kessler@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
src/math/big/int.go
src/math/big/int_test.go