A library providing a arbitrary length integer implementation for Node and browser javascript coding.
This library was put together as an implementation of Programming Praxis "Big Number" exercises in 2011.
@dayspringpartners/big-number
npm install @dayspringpartners/big-number --save
In Typescript
import { BigNumber } from '@dayspringpartners/big-number';
const oneThousand = new BigNumber(1000);
const bigger = new BigNumber(123456789);
console.log(bigger.add(oneThousand).toNumber());
console.log(oneThousand.add(5).toNumber());
console.log(oneThousand.subtract(oneThousand).toNumber());
In Javascript
const BigNumber = require('@dayspringpartners/big-number').BigNumber;
var oneThousand = new BigNumber(1000);
var bigger = new BigNumber(123456789);
console.log(bigger.add(oneThousand).toNumber());
console.log(oneThousand.add(5).toNumber());
console.log(oneThousand.subtract(oneThousand).toNumber());
Scan the string number representation and return a BigNumber. The scanned string can have two forms based on the forms used for number literals in PostScript (but more relaxed).
The first form is a string representing a decimal integer consisting of an optional sign followed by one or more decimal digits. The number is interpreted as a signed decimal integer and is converted to a BigNumber object.
The second form is a string representing a radix number and takes the form base#number, where base is a decimal integer in the range 2 through 36. The number is then interpreted in this base; it must consist of an optional sign followed by digits ranging from 0 to base - 1. Digits greater than 9 are represented by the letters A through Z (or a through z). The resulting number is treated as a signed integer and is converted to a BigNumber object. The notation is intended for specifying integers in a non-decimal radix, such as binary, octal, or hexadecimal.
Return text representation of the BigNumber object.
- base is the base used to represent the integer value. base is an integer in the range 2 through 36. The default for base is 10.
- parsable is an optional boolean value. If parsable is true the output text representation will have the form base#number (if base != 10). If parsable is false the output text representation will have the form number. The default for parsable is false.
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code.
$ git clone ....
$ npm install
$ npm run test:watch
$ npm run test
$ npm run lint
$ npm run format
$ npm verion patch|minor|major
# have an up-to-date working directory
$ npm verion patch|minor|major
$ npm login
$ npm publish
-
1.0.3 Fifth Release
- Some refactoring of code and tests.
- Changed the text representation of the value used by parseString and toString methods. The text representation is now based on the specification of integer literals used by PostScript language.
-
1.0.2 Fourth Release
Completed implementation with division and string representation parsing and printing.
-
1.0.1 Third Release
Changed implementation to be be in Typescript. Updated to a hosted npm package.
-
0.2.0 Second Release
Completed Programming Praxis excercise "Big Numbers: Addition, Subtraction, And Multiplication": May 31, 2011
-
0.1.0 First Release
Completed Programming Praxis excercise "Big Numbers: Getting Started": May 24, 2011