linear-arbitrary-precision
Abstraction for linear functionality in big.js, bignumber.js, decimal.js and others via adapters.
Install
npm i linear-arbitrary-precision
Usage
See 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 = ;var adapter = ; // See adapters section for full list var Decimal = ; Decimal; // => 20 '1'; // => '0.33333333333333333333' Decimal; '1'; // => '0.33333'
Operations
'0.1'; // => '0.3''0.3'; // => '0.2''0.6'; // => '1.8''0.3'; // => '1.5' '1'; // => true'1'; // => false
toString, valueOf and toJSON
var decimalThird = '1'; // with bigjs-adapter (other adapters might have differing implementations)decimalThird === decimalThird === decimalThird; // => true NumberdecimalThird; // => 1/3
JSON.stringify and JSON.parse with reviver
var Decimal40 = ; Decimal40; var decimalThird = '1'; var stringified = JSON;// => '"0.3333333333333333333333333333333333333333"' JSON;// => new Decimal40('0.3333333333333333333333333333333333333333')
See spec.
Related projects
- 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].