math-absolute-difference
v1.0.0
Published
Computes the absolute difference of two real numbers.
Downloads
8
Maintainers
Readme
Absolute Difference
Computes the absolute difference of two real numbers.
The absolute difference of two real numbers
is defined as the absolute value of their difference.
Installation
$ npm install math-absolute-difference
Usage
var diff = require( 'math-absolute-difference' );
diff( x, y )
Computes the absolute difference of two real numbers.
var d = diff( 2, 5 );
// returns 3
d = diff( -1, 3.14 );
// returns ~4.14
d = diff( 10.1, -2.05 );
// returns ~12.15
d = diff( -0, 0 );
// returns 0
d = diff( NaN, 5 );
// returns NaN
d = diff( 5, NaN );
// returns NaN
var PINF = Number.POSITIVE_INFINITY;
var NINF = Number.NEGATIVE_INFINITY;
d = diff( PINF, PINF );
// returns NaN
d = diff( NINF, NINF );
// returns NaN
d = diff( PINF, NINF );
// returns +infinity
d = diff( NINF, PINF );
// returns +infinity
Examples
var diff = require( 'math-absolute-difference' );
var x;
var y;
var d;
var i;
for ( i = 0; i < 100; i++ ) {
x = Math.random()*1e4 - 1e2;
y = Math.random()*1e4 - 1e2;
d = diff( x, y );
console.log( 'x = %d. y = %d. |x-y| = %d.', x, y, d );
}
To run the example code from the top-level application directory,
$ node ./examples/index.js
Tests
Unit
This repository uses tape for unit tests. To run the tests, execute the following command in the top-level application directory:
$ make test
All new feature development should have corresponding unit tests to validate correct functionality.
Test Coverage
This repository uses Istanbul as its code coverage tool. To generate a test coverage report, execute the following command in the top-level application directory:
$ make test-cov
Istanbul creates a ./reports/coverage
directory. To access an HTML version of the report,
$ make view-cov
Browser Support
This repository uses Testling for browser testing. To run the tests in a (headless) local web browser, execute the following command in the top-level application directory:
$ make test-browsers
To view the tests in a local web browser,
$ make view-browser-tests
License
Copyright
Copyright © 2016. The Compute.io Authors.