Logo

Programming-Idioms

  • Java

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 java.math.BigInteger;
BigInteger z = x.pow(n);

This leaves x unchanged.
using System.Numerics;
var z = BigInteger.Pow(x, n);

New implementation...