better-math
Mathematical operations performed reliably and intuitively
Why?
- No ugly approximation:
01 + 02 // => 0.30000000000000004 math // => 0.3
- No messy unpredictable type conversion:
1 + '1' // => '11' true - 1 // => 0 + 11 // => '1.1' - 11 // => '-1.1' {} + 11 // => 1.1 math // => Uncaught Error: Both arguments must be finite numbers math // => Uncaught Error: Both arguments must be finite numbers math // => Uncaught Error: Both arguments must be finite numbers math // => Uncaught Error: Both arguments must be finite numbers math // => Uncaught Error: Both arguments must be finite numbers
Install
$ npm install --save better-math
Usage
var math = math // => 0.3math // => -0.1
API
math.add (number1, number2)
number1, number2
Type: real number
for both arguments strictly enforced with no exceptions!
No Infinities
, no NaN
s, no null
, no strings (not even '1'
!):
if ! || ! throw Error'Both arguments must be finite numbers'
Status
Currently .add
is implemented and thoroughly tested
Credit
- This library is a tiny wrapper around the wonderful arbitrary-precision decimal arithmetic library Big.js that deserves most credit
- The (also wonderful)) LoDash is used for type checking
License
MIT © Dmitri Zaitsev