fast-exponential

1.0.4 • Public • Published

fast-exponential

An implementation of fast exponentiation that can calculate exponential for big numbers ideally in log(n) time complexity The large number is supported by BigInt, which unfortunatly is not in constant time when multyplicate with another large number. Therefore it is not strictly in log(N) time complexity.

Install

npm install fast-exponential

Params

/*
@param x This is the base
@param n This is the power
@param mod Optional modulus
@return x^n if mod is not specified, else x^n % mod
*/
fastExp(x,n,mod = null)

Usage

const fastExp = require("fast-exponential")
console.log(fastExp(2,10)) //1024
n = "1139631134290681913324518075250462509444792614577115360833700594253534083115108212461164873379591734542309312064780949257819665132832661342154198437454459926525649486600336464897081397167045104842672493488133506984881500857942197501"
M = "3141592651842593"
d = "20729576806810227945651433503304642530313216592724403339332811669890870"
+"507980537712665435487675836653308618504240738644446969730044899317107941502"
+"247799584959444798172916891463972996495752944622965018659022099059225470003"
+"8562058305"
console.log(fastExp(M,d,n))
//450185963693909864026895836829398229699587317498476752798024488061316488533033295859758263339821291798020665834789679241243278095751940650540713944197579512398507578002732869853224053105027949343093018580947275265543427402941263699n

Test

npm test

Contribute

https://github.com/zhan006/fast-exp

Readme

Keywords

none

Package Sidebar

Install

npm i fast-exponential

Weekly Downloads

2

Version

1.0.4

License

ISC

Unpacked Size

8.62 kB

Total Files

5

Last publish

Collaborators

  • whizwang