README.md (2223B)
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 [double-precision floating-point epsilon][@stdlib/constants/float64/eps]. 24 25 <section class="usage"> 26 27 ## Usage 28 29 ```javascript 30 var FLOAT64_SQRT_EPSILON = require( '@stdlib/constants/float64/sqrt-eps' ); 31 ``` 32 33 #### FLOAT64_SQRT_EPSILON 34 35 [Square root][@stdlib/math/base/special/sqrt] of [double-precision floating-point epsilon][@stdlib/constants/float64/eps]. 36 37 ```javascript 38 var bool = ( FLOAT64_SQRT_EPSILON === 0.14901161193847656e-7 ); 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 randu = require( '@stdlib/random/base/randu' ); 56 var FLOAT64_SQRT_EPSILON = require( '@stdlib/constants/float64/sqrt-eps' ); 57 58 var bool; 59 var a; 60 var b; 61 var i; 62 63 function isApprox( a, b ) { 64 var delta; 65 var tol; 66 67 delta = abs( a - b ); 68 tol = FLOAT64_SQRT_EPSILON * max( abs( a ), abs( b ) ); 69 70 return ( delta <= tol ); 71 } 72 73 for ( i = 0; i < 100; i++ ) { 74 a = randu() * 10.0; 75 b = a + (randu()*5.0e-7) - 2.5e-7; 76 bool = isApprox( a, b ); 77 console.log( '%d %s approximately equal to %d. Delta: %d.', a, ( bool ) ? 'is' : 'is not', b, abs( a - b ) ); 78 } 79 ``` 80 81 </section> 82 83 <!-- /.examples --> 84 85 <section class="links"> 86 87 [@stdlib/math/base/special/sqrt]: https://www.npmjs.com/package/@stdlib/math-base-special-sqrt 88 89 [@stdlib/constants/float64/eps]: https://www.npmjs.com/package/@stdlib/constants/tree/main/float64/eps 90 91 </section> 92 93 <!-- /.links -->