**Update(December2,2018):**[`BigInt` is being added as a native feature of JavaScript](https://tc39.github.io/proposal-bigint/). This library now works as a polyfill: if the environment supports the native `BigInt`,thislibraryactsasathinwrapperoverthenativeimplementation.
##Installation
Ifyouareusingabrowser,youcandownload[BigInteger.jsfromGitHub](http://peterolson.github.com/BigInteger.js/BigInteger.min.js) or just hotlink to it:
Ifyouprovideasecondparameter,thenitwillparse`number` as a number in base `base`. Note that `base` can be any bigInt (even negative or zero). The letters "a-z" and "A-Z" will be interpreted as the numbers 10 to 35. Higher digits can be specified in angle brackets (`<` and `>`). The default `base` is `10`.
Youcanspecifyacustomalphabetforbaseconversionwiththethirdparameter.Thedefault`alphabet` is `"0123456789abcdefghijklmnopqrstuvwxyz"`.
Thefourthparameterspecifieswhetherornotthenumberstringshouldbecase-sensitive,i.e.whether`a` and `A` should be treated as different digits. By default `caseSensitive` is `false`.
NotethatJavascriptnumberslargerthan`9007199254740992` and smaller than `-9007199254740992`arenotpreciselyrepresentednumbersandwillnotproduceexactresults.Ifyouaredealingwithnumbersoutsidethatrange,itisbettertopassinstrings.
-`bigInt(5)` => `3` (since 5 is `101`inbinary,whichisthreedigitslong)
####`compare(number)`
Performsacomparisonbetweentwonumbers.Ifthenumbersareequal,itreturns`0`. If the first number is greater, it returns `1`. If the first number is lesser, it returns `-1`.
Returns`true` if the number is very likely to be prime, `false`otherwise.
Supplying`iterations` is optional - it determines the number of iterations of the test (default: `5`).Themoreiterations,thelowerchanceofgettingafalsepositive.
Notethatthisfunctionisnotdeterministic,sinceitreliesonrandomsamplingoffactors,sotheresultforsomenumbersisnotalwaysthesame-unlessyoupassapredictablerandomnumbergeneratoras`rng`. The behavior and requirements are the same as with `randBetween`.
Shiftsthenumberleftby`n` places in its binary representation. If a negative number is provided, it will shift right. Throws an error if `n` is outside of the range `[-9007199254740992, 9007199254740992]`.
-`bigInt(8).shiftLeft(2)` => `32`
-`bigInt(8).shiftLeft(-2)` => `2`
####`shiftRight(n)`
Shiftsthenumberrightby`n` places in its binary representation. If a negative number is provided, it will shift left. Throws an error if `n` is outside of the range `[-9007199254740992, 9007199254740992]`.
ConvertsabigInttoastring.Thereisanoptionalradixparameter(whichdefaultsto10)thatconvertsthenumbertothegivenradix.Digitsintherange`10-35` will use the letters `a-z`.
-`bigInt("1e9").toString()` => `"1000000000"`
-`bigInt("1e9").toString(16)` => `"3b9aca00"`
Youcanuseacustombasealphabetwiththesecondparameter.Thedefault`alphabet` is `"0123456789abcdefghijklmnopqrstuvwxyz"`.
-`bigInt("5").toString(2, "aA")` => `"AaA"`
**Notethatarithmeticaloperatorswilltriggerthe`valueOf` function rather than the `toString` function.** When converting a bigInteger to a string, you should use the `toString` method or the `String`functioninsteadofaddingtheemptystring.
Theunittestsarecontainedinthe`spec/spec.js` file. You can run them locally by opening the `spec/SpecRunner.html` or file or running `npm test`.Youcanalso[runthetestsonlinefromGitHub](http://peterolson.github.io/BigInteger.js/spec/SpecRunner.html).