time-to-botec

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

README.md (2350B)


      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 # Square Root of Epsilon
     22 
     23 > [Square root][@stdlib/math/base/special/sqrt] of [single-precision floating-point epsilon][@stdlib/constants/float32/eps].
     24 
     25 <section class="usage">
     26 
     27 ## Usage
     28 
     29 ```javascript
     30 var FLOAT32_SQRT_EPSILON = require( '@stdlib/constants/float32/sqrt-eps' );
     31 ```
     32 
     33 #### FLOAT32_SQRT_EPSILON
     34 
     35 [Square root][@stdlib/math/base/special/sqrt] of [single-precision floating-point epsilon][@stdlib/constants/float32/eps].
     36 
     37 ```javascript
     38 var bool = ( FLOAT32_SQRT_EPSILON === 0.0003452669770922512 );
     39 // returns true
     40 ```
     41 
     42 </section>
     43 
     44 <!-- /.usage -->
     45 
     46 <section class="examples">
     47 
     48 ## Examples
     49 
     50 <!-- eslint no-undef: "error" -->
     51 
     52 ```javascript
     53 var abs = require( '@stdlib/math/base/special/abs' );
     54 var max = require( '@stdlib/math/base/special/max' );
     55 var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' );
     56 var randu = require( '@stdlib/random/base/randu' );
     57 var FLOAT32_SQRT_EPSILON = require( '@stdlib/constants/float32/sqrt-eps' );
     58 
     59 var bool;
     60 var a;
     61 var b;
     62 var i;
     63 
     64 function isApprox( a, b ) {
     65     var delta;
     66     var tol;
     67 
     68     delta = float64ToFloat32( abs( a - b ) );
     69     tol = float64ToFloat32( FLOAT32_SQRT_EPSILON * max( abs( a ), abs( b ) ) );
     70 
     71     return ( delta <= tol );
     72 }
     73 
     74 for ( i = 0; i < 100; i++ ) {
     75     a = float64ToFloat32( randu()*10.0 );
     76     b = float64ToFloat32( a + (randu()*2.0e-2) - 1.0e-2 );
     77     bool = isApprox( a, b );
     78     console.log( '%d %s approximately equal to %d', a, ( bool ) ? 'is' : 'is not', b );
     79 }
     80 ```
     81 
     82 </section>
     83 
     84 <!-- /.examples -->
     85 
     86 <section class="links">
     87 
     88 [@stdlib/math/base/special/sqrt]: https://www.npmjs.com/package/@stdlib/math-base-special-sqrt
     89 
     90 [@stdlib/constants/float32/eps]: https://www.npmjs.com/package/@stdlib/constants/tree/main/float32/eps
     91 
     92 </section>
     93 
     94 <!-- /.links -->