fast-mod-exp
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

Fast Mod Exp

Fast modular exponentiation function, for numbers and bigints.

Install

npm install --save fast-mod-exp

Usage

This is equivalent to doing ( a ** b ) % n, assuming bigints or infinite precision, but way faster in many cases.

import fme from 'fast-mod-exp';

{ // It works with bigints
  const a = 123n;
  const b = 23n;
  const n = 531n;
  const result = fme ( a, b, n ); // => 171n
}

{ // It works with numbers also
  const a = 123;
  const b = 23;
  const n = 531;
  const result = fme ( a, b, n ); // => 171
}

License

MIT © Fabio Spampinato

Package Sidebar

Install

npm i fast-mod-exp

Weekly Downloads

720

Version

1.0.0

License

none

Unpacked Size

5.72 kB

Total Files

10

Last publish

Collaborators

  • fabiospampinato