time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

README.md (2744B)


      1 <!--
      2 
      3 @license Apache-2.0
      4 
      5 Copyright (c) 2018 The Stdlib Authors.
      6 
      7 Licensed under the Apache License, Version 2.0 (the "License");
      8 you may not use this file except in compliance with the License.
      9 You may obtain a copy of the License at
     10 
     11    http://www.apache.org/licenses/LICENSE-2.0
     12 
     13 Unless required by applicable law or agreed to in writing, software
     14 distributed under the License is distributed on an "AS IS" BASIS,
     15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     16 See the License for the specific language governing permissions and
     17 limitations under the License.
     18 
     19 -->
     20 
     21 # Absolute Difference
     22 
     23 > Compute the [absolute difference][absolute-difference] of two real numbers.
     24 
     25 <section class="intro">
     26 
     27 The [absolute difference][absolute-difference] of two real `numbers` is defined as the absolute value of their difference.
     28 
     29 <!-- <equation class="equation" label="eq:absolute_difference" align="center" raw="|\Delta| = | x - y |" alt="Absolute difference"> -->
     30 
     31 <div class="equation" align="center" data-raw-text="|\Delta| = | x - y |" data-equation="eq:absolute_difference">
     32     <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@bb29798906e119fcb2af99e94b60407a270c9b32/lib/node_modules/@stdlib/math/base/utils/absolute-difference/docs/img/equation_absolute_difference.svg" alt="Absolute difference">
     33     <br>
     34 </div>
     35 
     36 <!-- </equation> -->
     37 
     38 </section>
     39 
     40 <!-- /.intro -->
     41 
     42 <section class="usage">
     43 
     44 ## Usage
     45 
     46 ```javascript
     47 var absdiff = require( '@stdlib/math/base/utils/absolute-difference' );
     48 ```
     49 
     50 #### absdiff( x, y )
     51 
     52 Computes the [absolute difference][absolute-difference] of two real numbers.
     53 
     54 ```javascript
     55 var d = absdiff( 2.0, 5.0 );
     56 // returns 3.0
     57 
     58 d = absdiff( -1.0, 3.14 );
     59 // returns ~4.14
     60 
     61 d = absdiff( 10.1, -2.05 );
     62 // returns ~12.15
     63 
     64 d = absdiff( -0.0, 0.0 );
     65 // returns +0.0
     66 
     67 d = absdiff( NaN, 5.0 );
     68 // returns NaN
     69 
     70 d = absdiff( 5.0, NaN );
     71 // returns NaN
     72 
     73 d = absdiff( Infinity, Infinity );
     74 // returns NaN
     75 
     76 d = absdiff( -Infinity, -Infinity );
     77 // returns NaN
     78 
     79 d = absdiff( Infinity, -Infinity );
     80 // returns Infinity
     81 
     82 d = absdiff( -Infinity, Infinity );
     83 // returns Infinity
     84 ```
     85 
     86 </section>
     87 
     88 <!-- /.usage -->
     89 
     90 <section class="examples">
     91 
     92 ## Examples
     93 
     94 <!-- eslint no-undef: "error" -->
     95 
     96 ```javascript
     97 var randu = require( '@stdlib/random/base/randu' );
     98 var absdiff = require( '@stdlib/math/base/utils/absolute-difference' );
     99 
    100 var x;
    101 var y;
    102 var d;
    103 var i;
    104 
    105 for ( i = 0; i < 100; i++ ) {
    106     x = (randu()*1.0e4) - 1.0e2;
    107     y = (randu()*1.0e4) - 1.0e2;
    108     d = absdiff( x, y );
    109     console.log( 'x = %d. y = %d. |x-y| = %d.', x, y, d );
    110 }
    111 ```
    112 
    113 </section>
    114 
    115 <!-- /.examples -->
    116 
    117 <section class="links">
    118 
    119 [absolute-difference]: https://en.wikipedia.org/wiki/Absolute_difference
    120 
    121 </section>
    122 
    123 <!-- /.links -->