math-absolute-difference

1.0.0 • Public • Published

Absolute Difference

NPM version Build Status Coverage Status Dependencies

Computes the absolute difference of two real numbers.

The absolute difference of two real numbers is defined as the absolute value of their difference.

Absolute 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
 
= diff( -1, 3.14 );
// returns ~4.14
 
= diff( 10.1, -2.05 );
// returns ~12.15
 
= diff( -0, 0 );
// returns 0
 
= diff( NaN, 5 );
// returns NaN
 
= diff( 5, NaN );
// returns NaN
 
var PINF = Number.POSITIVE_INFINITY;
var NINF = Number.NEGATIVE_INFINITY;
 
= diff( PINF, PINF );
// returns NaN
 
= diff( NINF, NINF );
// returns NaN
 
= diff( PINF, NINF );
// returns +infinity
 
= 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

MIT license.

Copyright

Copyright © 2016. The Compute.io Authors.

Package Sidebar

Install

npm i math-absolute-difference

Weekly Downloads

1

Version

1.0.0

License

MIT

Last publish

Collaborators

  • kgryte