Nicer Perusal Method

    @stdlib/math-base-utils-absolute-difference
    TypeScript icon, indicating that this package has built-in type declarations

    0.0.6 • Public • Published

    Absolute Difference

    NPM version Build Status Coverage Status

    Compute 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 @stdlib/math-base-utils-absolute-difference

    Usage

    var absdiff = require( '@stdlib/math-base-utils-absolute-difference' );

    absdiff( x, y )

    Computes the absolute difference of two real numbers.

    var d = absdiff( 2.0, 5.0 );
    // returns 3.0
    
    d = absdiff( -1.0, 3.14 );
    // returns ~4.14
    
    d = absdiff( 10.1, -2.05 );
    // returns ~12.15
    
    d = absdiff( -0.0, 0.0 );
    // returns +0.0
    
    d = absdiff( NaN, 5.0 );
    // returns NaN
    
    d = absdiff( 5.0, NaN );
    // returns NaN
    
    d = absdiff( Infinity, Infinity );
    // returns NaN
    
    d = absdiff( -Infinity, -Infinity );
    // returns NaN
    
    d = absdiff( Infinity, -Infinity );
    // returns Infinity
    
    d = absdiff( -Infinity, Infinity );
    // returns Infinity

    Examples

    var randu = require( '@stdlib/random-base-randu' );
    var absdiff = require( '@stdlib/math-base-utils-absolute-difference' );
    
    var x;
    var y;
    var d;
    var i;
    
    for ( i = 0; i < 100; i++ ) {
        x = (randu()*1.0e4) - 1.0e2;
        y = (randu()*1.0e4) - 1.0e2;
        d = absdiff( x, y );
        console.log( 'x = %d. y = %d. |x-y| = %d.', x, y, d );
    }

    See Also


    Notice

    This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.

    For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.

    Community

    Chat


    License

    See LICENSE.

    Copyright

    Copyright © 2016-2022. The Stdlib Authors.

    Install

    npm i @stdlib/math-base-utils-absolute-difference

    Homepage

    stdlib.io

    DownloadsWeekly Downloads

    356

    Version

    0.0.6

    License

    Apache-2.0

    Unpacked Size

    43.2 kB

    Total Files

    10

    Last publish

    Collaborators

    • stdlib-bot
    • kgryte
    • planeshifter
    • rreusser