Merge pull request #3214 from rbehrends/fix-exponentiation

Fix exponentiation operation to avoid overflow.
This commit is contained in:
Dominik Picheta
2015-08-14 17:13:58 +01:00

View File

@@ -427,10 +427,12 @@ proc `^`*[T](x, y: T): T =
var (x, y) = (x, y)
result = 1
while y != 0:
while true:
if (y and 1) != 0:
result *= x
y = y shr 1
if y == 0:
break
x *= x
proc gcd*[T](x, y: T): T =