better-math

1.4.3 • Public • Published

better-math

Mathematical operations performed reliably and intuitively

PRs Welcome MIT License npm downloads

js-standard-style

Why?

  • No ugly approximation:
    0.1 + 0.2 // => 0.30000000000000004
    math.add(0.1, 0.2) // => 0.3
  • No messy unpredictable type conversion:
    1 + '1' // => '11'
    true - 1 // => 0
    [] + 1.1 // => '1.1'
    [] - 1.1 // => '-1.1'
    {} + 1.1 // => 1.1
 
    math.add(1, '1') // => Uncaught Error: Both arguments must be finite numbers
    math.add(true, -1) // => Uncaught Error: Both arguments must be finite numbers
    math.add([], 1.1) // => Uncaught Error: Both arguments must be finite numbers
    math.add([], 1.1) // => Uncaught Error: Both arguments must be finite numbers
    math.add({}, 1.1) // => Uncaught Error: Both arguments must be finite numbers

Install

$ npm install --save better-math

Usage

var math = require('better-math')
 
math.add(0.1, 0.2) // => 0.3
math.add(0.1, -0.2) // => -0.1

API

math.add (number1, number2)

number1, number2

Type: real number for both arguments strictly enforced with no exceptions!

No Infinities, no NaNs, no null, no strings (not even '1'!):

  if (!isFinite(x) || !isFinite(y)) throw Error('Both arguments must be finite numbers')

Status

Currently .add is implemented and thoroughly tested

Credit

License

MIT © Dmitri Zaitsev

Readme

Keywords

Package Sidebar

Install

npm i better-math

Weekly Downloads

0

Version

1.4.3

License

MIT

Last publish

Collaborators

  • dmitriz