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

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.

z = :math.pow(x, n)
using System.Numerics;
var z = BigInteger.Pow(x, n);
import std.bigint;
BigInt z = x ^^ n;
import "dart:math";
var z = pow(x, n);
import "math/big"
nb := big.NewInt(int64(n))
var z big.Int
z.Exp(x, nb, nil)
z = x ^ n
let z = x**n
import java.math.BigInteger;
BigInteger z = x.pow(n);
use bigint;
my ($x, $y) = (3 ** 200, 25);
my $z = $x ** $y;
z = x**n
z = x ** n
extern crate num;
let z = num::pow(x, n);

Do you know the best way to do this in your language ?
New implementation...

Idiom created by

programming-idioms.org

Related idioms