time-to-botec

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

README.md (3760B)


      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 the [absolute value][absolute-value] of a double-precision floating-point number.
     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@bb29798906e119fcb2af99e94b60407a270c9b32/lib/node_modules/@stdlib/math/base/special/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/abs' );
     48 ```
     49 
     50 #### abs( x )
     51 
     52 Computes the [absolute value][absolute-value] of a double-precision floating-point number.
     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( -0.0 );
     65 // returns 0.0
     66 
     67 v = abs( NaN );
     68 // returns NaN
     69 ```
     70 
     71 </section>
     72 
     73 <!-- /.usage -->
     74 
     75 <section class="examples">
     76 
     77 ## Examples
     78 
     79 <!-- eslint no-undef: "error" -->
     80 
     81 ```javascript
     82 var randu = require( '@stdlib/random/base/randu' );
     83 var round = require( '@stdlib/math/base/special/round' );
     84 var abs = require( '@stdlib/math/base/special/abs' );
     85 
     86 var rand;
     87 var i;
     88 
     89 for ( i = 0; i < 100; i++ ) {
     90     rand = round( randu() * 100.0 ) - 50.0;
     91     console.log( 'abs(%d) = %d', rand, abs( rand ) );
     92 }
     93 ```
     94 
     95 </section>
     96 
     97 <!-- /.examples -->
     98 
     99 <!-- C interface documentation. -->
    100 
    101 * * *
    102 
    103 <section class="c">
    104 
    105 ## C APIs
    106 
    107 <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
    108 
    109 <section class="intro">
    110 
    111 </section>
    112 
    113 <!-- /.intro -->
    114 
    115 <!-- C usage documentation. -->
    116 
    117 <section class="usage">
    118 
    119 ### Usage
    120 
    121 ```c
    122 #include "stdlib/math/base/special/abs.h"
    123 ```
    124 
    125 #### stdlib_base_abs( x )
    126 
    127 Computes the absolute value of a double-precision floating-point number.
    128 
    129 ```c
    130 double y = stdlib_base_abs( -5.0 );
    131 // returns 5.0
    132 ```
    133 
    134 The function accepts the following arguments:
    135 
    136 -   **x**: `[in] double` input value.
    137 
    138 ```c
    139 double stdlib_base_abs( const double x );
    140 ```
    141 
    142 </section>
    143 
    144 <!-- /.usage -->
    145 
    146 <!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
    147 
    148 <section class="notes">
    149 
    150 </section>
    151 
    152 <!-- /.notes -->
    153 
    154 <!-- C API usage examples. -->
    155 
    156 <section class="examples">
    157 
    158 ### Examples
    159 
    160 ```c
    161 #include "stdlib/math/base/special/abs.h"
    162 #include <stdio.h>
    163 
    164 int main() {
    165     double x[] = { 3.14, -3.14, 0.0, 0.0/0.0 };
    166 
    167     double y;
    168     int i;
    169     for ( i = 0; i < 4; i++ ) {
    170         y = stdlib_base_abs( x[ i ] );
    171         printf( "|%lf| = %lf\n", x[ i ], y );
    172     }
    173 }
    174 ```
    175 
    176 </section>
    177 
    178 <!-- /.examples -->
    179 
    180 </section>
    181 
    182 <!-- /.c -->
    183 
    184 <section class="links">
    185 
    186 [absolute-value]: https://en.wikipedia.org/wiki/Absolute_value
    187 
    188 </section>
    189 
    190 <!-- /.links -->