time-to-botec

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

README.md (3978B)


      1 <!--
      2 
      3 @license Apache-2.0
      4 
      5 Copyright (c) 2019 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 # Reciprocal Square Root
     22 
     23 > Compute the reciprocal of the principal [square root][square-root] of a double-precision floating-point number.
     24 
     25 <section class="intro">
     26 
     27 The reciprocal of the principal [square root][square-root] is defined as
     28 
     29 <!-- <equation class="equation" label="eq:reciprocal_square_root" align="center" raw="\operatorname{rsqrt}(x)=\frac{1}{\sqrt{x}}" alt="Reciprocal square root"> -->
     30 
     31 <div class="equation" align="center" data-raw-text="\operatorname{rsqrt}(x)=\frac{1}{\sqrt{x}}" data-equation="eq:reciprocal_square_root">
     32     <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@5b8dab9d7f516fcc8e1741900ae1569e95470c73/lib/node_modules/@stdlib/math/base/special/rsqrt/docs/img/equation_reciprocal_square_root.svg" alt="Reciprocal square root">
     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 rsqrt = require( '@stdlib/math/base/special/rsqrt' );
     48 ```
     49 
     50 #### rsqrt( x )
     51 
     52 Computes the reciprocal (inverse) square root of a double-precision floating-point number.
     53 
     54 ```javascript
     55 var v = rsqrt( 1.0 );
     56 // returns 1.0
     57 
     58 v = rsqrt( 4.0 );
     59 // returns 0.5
     60 
     61 v = rsqrt( 100.0 );
     62 // returns 0.1
     63 
     64 v = rsqrt( 0.0 );
     65 // returns Infinity
     66 
     67 v = rsqrt( NaN );
     68 // returns NaN
     69 
     70 v = rsqrt( Infinity );
     71 // returns 0.0
     72 ```
     73 
     74 For negative numbers, the reciprocal square root is **not** defined.
     75 
     76 ```javascript
     77 var v = rsqrt( -4.0 );
     78 // returns NaN
     79 ```
     80 
     81 </section>
     82 
     83 <!-- /.usage -->
     84 
     85 <section class="examples">
     86 
     87 ## Examples
     88 
     89 <!-- eslint no-undef: "error" -->
     90 
     91 ```javascript
     92 var randu = require( '@stdlib/random/base/randu' );
     93 var round = require( '@stdlib/math/base/special/round' );
     94 var rsqrt = require( '@stdlib/math/base/special/rsqrt' );
     95 
     96 var x;
     97 var i;
     98 
     99 for ( i = 0; i < 100; i++ ) {
    100     x = round( randu() * 100.0 );
    101     console.log( 'rsqrt(%d) = %d', x, rsqrt( x ) );
    102 }
    103 ```
    104 
    105 </section>
    106 
    107 <!-- /.examples -->
    108 
    109 <!-- C interface documentation. -->
    110 
    111 * * *
    112 
    113 <section class="c">
    114 
    115 ## C APIs
    116 
    117 <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
    118 
    119 <section class="intro">
    120 
    121 </section>
    122 
    123 <!-- /.intro -->
    124 
    125 <!-- C usage documentation. -->
    126 
    127 <section class="usage">
    128 
    129 ### Usage
    130 
    131 ```c
    132 #include "stdlib/math/base/special/rsqrt.h"
    133 ```
    134 
    135 #### stdlib_base_rsqrt( x )
    136 
    137 Computes the reciprocal (inverse) [square root][square-root] of a double-precision floating-point number.
    138 
    139 ```c
    140 double y = stdlib_base_rsqrt( 4.0 );
    141 // returns 0.5
    142 ```
    143 
    144 The function accepts the following arguments:
    145 
    146 -   **x**: `[in] double` input value.
    147 
    148 ```c
    149 double stdlib_base_rsqrt( const double x );
    150 ```
    151 
    152 </section>
    153 
    154 <!-- /.usage -->
    155 
    156 <!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
    157 
    158 <section class="notes">
    159 
    160 </section>
    161 
    162 <!-- /.notes -->
    163 
    164 <!-- C API usage examples. -->
    165 
    166 <section class="examples">
    167 
    168 ### Examples
    169 
    170 ```c
    171 #include "stdlib/math/base/special/rsqrt.h"
    172 #include <stdio.h>
    173 
    174 int main() {
    175     double x[] = { 3.14, 9.0, 0.0, 0.0/0.0 };
    176 
    177     double y;
    178     int i;
    179     for ( i = 0; i < 4; i++ ) {
    180         y = stdlib_base_rsqrt( x[ i ] );
    181         printf( "rsqrt(%lf) = %lf\n", x[ i ], y );
    182     }
    183 }
    184 ```
    185 
    186 </section>
    187 
    188 <!-- /.examples -->
    189 
    190 </section>
    191 
    192 <!-- /.c -->
    193 
    194 <section class="links">
    195 
    196 [square-root]: https://en.wikipedia.org/wiki/Square_root
    197 
    198 </section>
    199 
    200 <!-- /.links -->