time-to-botec

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

README.md (2750B)


      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 Value
     22 
     23 > Compute an [absolute value][absolute-value].
     24 
     25 <section class="intro">
     26 
     27 The [absolute value][absolute-value] is defined as
     28 
     29 <!-- <equation class="equation" label="eq:absolute_value" align="center" raw="|x| = \begin{cases} x & \textrm{if}\ x \geq 0 \\ -x & \textrm{if}\ x < 0\end{cases}" alt="Absolute value"> -->
     30 
     31 <div class="equation" align="center" data-raw-text="|x| = \begin{cases} x &amp; \textrm{if}\ x \geq 0 \\ -x &amp; \textrm{if}\ x &lt; 0\end{cases}" data-equation="eq:absolute_value">
     32     <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@c1bdd27898df04d752ddb2dca37ca049e4c94d9b/lib/node_modules/@stdlib/math/base/special/fast/abs/docs/img/equation_absolute_value.svg" alt="Absolute value">
     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 abs = require( '@stdlib/math/base/special/fast/abs' );
     48 ```
     49 
     50 #### abs( x )
     51 
     52 Computes an [absolute value][absolute-value].
     53 
     54 ```javascript
     55 var v = abs( -1.0 );
     56 // returns 1.0
     57 
     58 v = abs( 2.0 );
     59 // returns 2.0
     60 
     61 v = abs( 0.0 );
     62 // returns 0.0
     63 
     64 v = abs( NaN );
     65 // returns NaN
     66 ```
     67 
     68 </section>
     69 
     70 <!-- /.usage -->
     71 
     72 <!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
     73 
     74 <section class="notes">
     75 
     76 ## Notes
     77 
     78 -   This implementation is **not** [IEEE 754][ieee754] compliant. If provided `-0`, the function returns `-0`.
     79 
     80     ```javascript
     81     var v = abs( -0.0 );
     82     // returns -0.0
     83     ```
     84 
     85 </section>
     86 
     87 <!-- /.notes -->
     88 
     89 <section class="examples">
     90 
     91 ## Examples
     92 
     93 <!-- eslint no-undef: "error" -->
     94 
     95 ```javascript
     96 var randu = require( '@stdlib/random/base/randu' );
     97 var round = require( '@stdlib/math/base/special/round' );
     98 var abs = require( '@stdlib/math/base/special/fast/abs' );
     99 
    100 var rand;
    101 var i;
    102 
    103 for ( i = 0; i < 100; i++ ) {
    104     rand = round( randu() * 100.0 ) - 50.0;
    105     console.log( 'abs(%d) = %d', rand, abs( rand ) );
    106 }
    107 ```
    108 
    109 </section>
    110 
    111 <!-- /.examples -->
    112 
    113 <section class="links">
    114 
    115 [absolute-value]: https://en.wikipedia.org/wiki/Absolute_value
    116 
    117 [ieee754]: https://en.wikipedia.org/wiki/IEEE_754-1985
    118 
    119 </section>
    120 
    121 <!-- /.links -->