core-arbitrary-precision
v3.1.1
Published
Core arbitrary precision abstraction
Downloads
95
Maintainers
Readme
core-arbitrary-precision
Abstraction for core arbitrary precision functionality in big.js, bignumber.js, decimal.js and others via adapters.
Install
npm i core-arbitrary-precision
Usage
Pending CodePen example.
Adapters
- [adapter] [lib] linear-big.js
- [adapter] [lib] big.js
- [adapter] [lib] bignumber.js
- [adapter] [lib] decimal.js
- [adapter] [lib] bigdecimal.js
- [adapter] [lib] floating
- [adapter] [lib] linear-converter
- [adapter] [lib] statistics-module
See up to date list.
Factory and configuration
var decimalFactory = require('core-arbitrary-precision');
var adapter = require('bigjs-adapter'); // See adapters section for full list
var Decimal = decimalFactory(adapter);
Decimal.getPrecision(); // => 20
Decimal.setPrecision(5);
Decimal.getPrecision(); // => 5
Operations
This core package has no operations, but they can be added:
new Decimal('2').pow(new Decimal('3')).valueOf(); // => Error!
var Decimal = require('pow-arbitrary-precision')(Decimal);
new Decimal('2').pow(new Decimal('3')).valueOf(); // => '8'
toString, valueOf and toJSON
var decimalOne = new Decimal('1');
// with bigjs-adapter (other adapters might have differing implementations)
decimalOne.toString() === decimalOne.valueOf() === decimalOne.toJSON(); // => true
Number(decimalThird); // => 1
JSON.stringify and JSON.parse with reviver
var decimalOne = new Decimal('1');
var stringified = JSON.stringify(decimalOne); // => '"1"'
JSON.parse(stringified, decimalOne.reviver); // => new decimalOne('1')
See spec.
Related projects
- arbitrary-precision: Arbitrary precision abstraction.
- linear-arbitrary-precision: Linear arbitrary precision abstraction.
- linear-converter: flexible linear converter with built in conversions for common units.
- linear-conversion: Linear conversion class for linear-converter.
- rescale: rescales a point given two scales.
- rescale-util: Rescale utilities.
- scale: scales normalised data.
- normalise: normalise data to [0, 1].