alibaba-archive / node-biginteger

node.js version of java.math.BigInteger
10 stars 5 forks source link

node-biginteger

This library is based on java.math.BigInteger Dependency Long

example

  $ npm install node-biginteger

  var BigInteger = require('node-biginteger');
  var n = BigInteger.fromString('abc', 16);
  n.toString(16);

Class Method: BigInteger.fromLong(val)

Class Method: BigInteger.fromString(val, [radix])

Class Method: BigInteger.fromBuffer(signum, magnitude)

n.toBuffer()

n.toString()

n.abs()

n.negate()

n.longValue()

n.add(val)

n.subtract(val)

n.multiply(val)

n.and(val)

n.andNot(val)

n.not()

n.pow(exponent)

  var n = BigInteger.fromString('2', 10);
  var n1 = n.pow(2);
  console.log(n1.toString());
  // 4

n.divide(val)

n.remainder(val)

Benchmark

$ node beanchmark.js

  BigInteger#multiply x 68,912 ops/sec ±0.50% (100 runs sampled)
  bignum#mul x 40,709 ops/sec ±1.30% (90 runs sampled)
  BigInteger#modPow(long) x 79.62 ops/sec ±0.98% (71 runs sampled)
  bignum#powm(long) x 22,901 ops/sec ±2.43% (92 runs sampled)
  BigInteger#modPow(short) x 134,965 ops/sec ±1.19% (97 runs sampled)
  bignum#powm(short) x 55,922 ops/sec ±2.84% (91 runs sampled)

License

MIT