#BigJS
This is my big integer library, it is built on top of the big int library built by Leemon Baird.
I built it for my own interests in cryptography. It was built as Leemon's library polluted the global scope and had a somewhat scattered design. I especially love the implementations that were done for finding primes. Enjoy!
Construction
BI(number, base)
number
- the actual number, this can be a string, a JS number, or another BI object
base
- this defaults to 10
var BI = require('bigjs');
var b = new BI(16772625);
var b = new BI("FFEE11", 16);
var foo = new BI(b);
.toString(base)
base
- this also defaults to 10
var b = new BI(16772625).toString(16);
.valueOf()
this only works by translating whatever is in the big int to a JS number. It's called whenever the object is involved in a numerical operation.
var b = (new BI(10)) * 2
Constants
BI.ONE == 1
BI.ZERO == 0
Primes
prime(bits, probable)
bits
- bit size of the prime, anything over 2048bits is rather slow on most machines
probable
- determines whether or not this is a true prime or a probable prime. Setting this to true means that 1 in every 2^80 numbers generated may be composite. However, it has a speed up of about 10x compared to the true prime.
BI.prime(2048)
Comparisons
Operations
Arithmetic
add(num, me)
var b = new BI(1997);
b.add(19);
b.add(19, true);
subtract(num, me)
var b = new BI(2016);
b.subtract(19);
b.subtract(19, true);
multiply(num, me)
var b = new BI(8);
b.multiply(7);
b.multiply(7, true);
times(num, me)
this is a synonym of .multiply()
Bitwise