Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Special cases for big_pow.
  • Loading branch information
colomon committed Apr 9, 2013
1 parent 65f862c commit f9c8fc2
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/Builtins.cs
Expand Up @@ -779,6 +779,15 @@ public partial class Builtins {

// Untested and probably unusable in the near term
public static BigInteger big_pow(BigInteger v1, BigInteger v2) {
if (v2 == BigInteger.Zero)
return BigInteger.One;
if (v1 == BigInteger.One)
return BigInteger.One;
if (v1 == BigInteger.Zero)
return BigInteger.Zero;
if (v1 == -BigInteger.One)
return v2 % 2 == 0 ? BigInteger.One : -BigInteger.One;

int CHUNK = 2000000000;
int margin = (int) (v2 % (BigInteger) CHUNK);
BigInteger number_chunks = (v2 - margin) / CHUNK;
Expand Down

0 comments on commit f9c8fc2

Please sign in to comment.