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

1.0.1 • Public • Published

Fast Mod Exp

Fast modular exponentiation function, for numbers and bigints.

Install

npm install 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 numbers
  const a = 123;
  const b = 23;
  const n = 531;
  const result = fme ( a, b, n ); // => 171
}

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

License

MIT © Fabio Spampinato

Package Sidebar

Install

npm i fast-mod-exp

Weekly Downloads

617

Version

1.0.1

License

MIT

Unpacked Size

3.15 kB

Total Files

5

Last publish

Collaborators

  • fabiospampinato