big-integer
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
BigInteger.js is a powerful library in JavaScript that essentially allows users to conduct arithmetic operations on integers with no limitations on their size. It fulfills that purpose by bypassing the size limit inherent in JavaScript's number data type, therefore eliminating any size-associated errors that may occur during the computation process. As of December 2, 2018, the library also functions as a polyfill, working as a wrapper over JavaScript's native BigInt if it is supported by the environment.
BigInteger.js can be utilized in various ways depending on whether the code is executed in a browser or through Node.js. If utilizing a browser, developers can either download BigInteger.js or hotlink directly to it. In a Node.js environment, BigInteger.js can be installed using npm and then simply requiring it in the code.
For instance, to use BigInteger.js in Node.js, the steps are as follows:
npm install big-integer
var bigInt = require("big-integer");
var bigNumber = bigInt("123456789012345678901234567890");
BigIntegers can be created by passing in a number, a string representing the number or another BigInteger to the bigInt
function. If you provide a second parameter, it will parse the passed number as a base base
number.
BigInteger.js also provides several methods for doing operations on BigInts such as addition (add
), subtraction (subtract
), multiplication (multiply
) and more.
Examples:
var sum = bigInt(5).add(7); // Returns a BigInteger representing "12"
var difference = bigInt(3).subtract(5); // Returns a BigInteger representing "-2"
var product = bigInt(111).multiply(111); // Returns a BigInteger representing "12321"
Note that operations performed using BigInteger.js return BigIntegers that allows for method chaining. A wide range of methods are available, from basic arithmetic to bitwise operations.
Documents related to BigInteger.js can be found in the README content of the library's GitHub repository. These documents provide comprehensive details about the library's installation, usage, its methods, and how to contribute to the project. If you are interested in running the test suite or the benchmarks, they are available in the repository as well. Other relevant information such as licensing information is also available in the repository.