time-to-botec

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

README.md (3902B)


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