]> Cypherpunks repositories - gostls13.git/commit
math/big: handle negative exponents in Exp
authorBrian Kessler <brian.m.kessler@gmail.com>
Wed, 13 Jun 2018 16:04:49 +0000 (10:04 -0600)
committerRobert Griesemer <gri@golang.org>
Thu, 14 Jun 2018 22:26:30 +0000 (22:26 +0000)
commit30b045d4d1a00801b1d1fc32a910334dcd722ba6
tree27179fa7be8a338ec1a9baf5e435ce8a1011596f
parente083dc6307b6593bdd44b219ffd21699d6f17fd7
math/big: handle negative exponents in Exp

For modular exponentiation, negative exponents can be handled using
the following relation.

for y < 0: x**y mod m == (x**(-1))**|y| mod m

First compute ModInverse(x, m) and then compute the exponentiation
with the absolute value of the exponent.  Non-modular exponentiation
with a negative exponent still returns 1.

Fixes #25865

Change-Id: I2a35986a24794b48e549c8de935ac662d217d8a0
Reviewed-on: https://go-review.googlesource.com/118562
Run-TryBot: Robert Griesemer <gri@golang.org>
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