Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Go

Idiom #66 Big integer exponentiation

Calculate the result z of x power n, where x is a big integer and n is a positive integer.

import "math/big"
nb := big.NewInt(int64(n))
var z big.Int
z.Exp(x, nb, nil)

Exponentiation is already implemented in package math/big.
using System.Numerics;
var z = BigInteger.Pow(x, n);

New implementation...