# math-float64-epsilon-difference

Computes the relative difference of two real numbers in units of double-precision floating-point epsilon.

## Usage no npm install needed!

``````<script type="module">
import mathFloat64EpsilonDifference from 'https://cdn.skypack.dev/math-float64-epsilon-difference';
</script>``````

# Relative Difference

Computes the relative difference of two real numbers in units of double-precision floating-point epsilon.

## Installation

``````\$ npm install math-float64-epsilon-difference
``````

## Usage

``````var diff = require( 'math-float64-epsilon-difference' );
``````

#### diff( x, y[, scale] )

Computes the relative difference of two real numbers in units of double-precision floating-point epsilon.

``````var d = diff( 12.15, 12.149999999999999 );
// returns ~0.658ε
``````

The following `scale` functions are supported:

• max-abs: maximum absolute value of `x` and `y` (default).
• max: maximum value of `x` and `y`.
• min-abs: minimum absolute value of `x` and `y`.
• min: minimum value of `x` and `y`.
• mean-abs: arithmetic mean of the absolute values of `x` and `y`.
• mean: arithmetic mean of `x` and `y`.
• x: `x` (noncommutative).
• y: `y` (noncommutative).

By default, the `function` scales the absolute difference by dividing the absolute difference by the maximum absolute value of `x` and `y`. To scale by a different `function`, specify a scale function name.

``````var d = diff( 2.4341309458983933, 2.4341309458633909, 'mean-abs' );
// returns ~64761.5ε => ~1.438e-11
``````

To use a custom scale `function`, provide a `function` which accepts two numeric arguments `x` and `y`.

``````function scale( x, y ) {
// Return the minimum value:
return ( x > y ) ? y : x;
}

var d = diff( 1.0000000000000002, 1.0000000000000100, scale );
// returns ~44ε
``````