What is jsbi?
JSBI is a pure-JavaScript implementation of the official ECMAScript BigInt proposal, which provides a way to represent whole numbers larger than 2^53 - 1, which is the largest number JavaScript can reliably represent with the Number primitive. JSBI is useful for performing arbitrary-precision arithmetic in JavaScript.
What are jsbi's main functionalities?
Arithmetic Operations
JSBI allows performing basic arithmetic operations such as addition, subtraction, multiplication, division, and finding the remainder between large integers.
const JSBI = require('jsbi');
const bigInt1 = JSBI.BigInt('123456789012345678901234567890');
const bigInt2 = JSBI.BigInt('987654321098765432109876543210');
const sum = JSBI.add(bigInt1, bigInt2);
const difference = JSBI.subtract(bigInt2, bigInt1);
const product = JSBI.multiply(bigInt1, bigInt2);
const quotient = JSBI.divide(bigInt2, bigInt1);
const remainder = JSBI.remainder(bigInt2, bigInt1);
Comparison Operations
JSBI can compare BigInt numbers to check for equality, or to see if one is greater than or less than another.
const JSBI = require('jsbi');
const bigInt1 = JSBI.BigInt('1234567890');
const bigInt2 = JSBI.BigInt('1234567890');
const bigInt3 = JSBI.BigInt('9876543210');
const isEqual = JSBI.equal(bigInt1, bigInt2); // true
const isLessThan = JSBI.lessThan(bigInt1, bigInt3); // true
const isGreaterThan = JSBI.greaterThan(bigInt3, bigInt1); // true
Bitwise Operations
JSBI supports bitwise operations such as AND, OR, and XOR, which are useful for manipulating large integers at the bit level.
const JSBI = require('jsbi');
const bigInt1 = JSBI.BigInt('1234567890');
const bigInt2 = JSBI.BigInt('9876543210');
const bitwiseAnd = JSBI.bitwiseAnd(bigInt1, bigInt2);
const bitwiseOr = JSBI.bitwiseOr(bigInt1, bigInt2);
const bitwiseXor = JSBI.bitwiseXor(bigInt1, bigInt2);
Other packages similar to jsbi
big-integer
big-integer is another arbitrary-precision integer arithmetic library for JavaScript. It offers similar functionalities to JSBI but also includes additional features like primality testing, which JSBI does not support.
bignumber.js
bignumber.js is a well-known library for working with large floating-point numbers as well as integers. It provides more features than JSBI, including support for decimal arithmetic and more advanced mathematical functions.