View source code
Display the source code in std/bigint.d from which thispage was generated on github.
Report a bug
If you spot a problem with this page, click here to create aGitHub issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.Requires a signed-in GitHub account. This works well for small changes.If you'd like to make larger changes you may want to consider usinglocal clone.

Function std.bigint.powmod

Fast power modulus calculation for BigInt operands.

BigInt powmod(
  BigInt base,
  BigInt exponent,
  BigInt modulus
) pure nothrow @safe;

Parameters

NameDescription
base the base BigInt operand.
exponent the exponent BigInt to raise base by.
modulus the BigInt modulus to use for the modular exponentiation.

Returns

The power modulus value of (base ^ exponent) % modulus.

Example

for powmod

BigInt base = BigInt("123456789012345678901234567890");
BigInt exponent = BigInt("1234567890123456789012345678901234567");
BigInt modulus = BigInt("1234567");

BigInt result = powmod(base, exponent, modulus);
writeln(result); // 359079

Authors

Don Clugston

License

Boost License 1.0.