time-to-botec

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

README.md (3960B)


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