README.md (2404B)
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 # Significand 22 23 > Return an integer corresponding to the significand of a [single-precision floating-point number][ieee754]. 24 25 <section class="usage"> 26 27 ## Usage 28 29 ```javascript 30 var significandf = require( '@stdlib/number/float32/base/significand' ); 31 ``` 32 33 #### significandf( x ) 34 35 Returns an `integer` corresponding to the significand of a [single-precision floating-point number][ieee754]. 36 37 ```javascript 38 var toFloat32 = require( '@stdlib/number/float64/base/to-float32' ); 39 40 var s = significandf( toFloat32( 3.14e34 ) ); // => 10000011000010001110111 41 // returns 4293751 42 43 s = significandf( toFloat32( 3.14e-34 ) ); // => 10100001011000001010101 44 // returns 5288021 45 46 s = significandf( toFloat32( -3.14 ) ); // => 10010001111010111000011 47 // returns 4781507 48 49 s = significandf( 0.0 ); // => 00000000000000000000000 50 // returns 0 51 52 s = significandf( NaN ); // => 10000000000000000000000 53 // returns 4194304 54 ``` 55 56 </section> 57 58 <!-- /.usage --> 59 60 <section class="examples"> 61 62 ## Examples 63 64 <!-- eslint no-undef: "error" --> 65 66 ```javascript 67 var randu = require( '@stdlib/random/base/randu' ); 68 var round = require( '@stdlib/math/base/special/round' ); 69 var pow = require( '@stdlib/math/base/special/pow' ); 70 var toFloat32 = require( '@stdlib/number/float64/base/to-float32' ); 71 var significandf = require( '@stdlib/number/float32/base/significand' ); 72 73 var frac; 74 var exp; 75 var x; 76 var s; 77 var i; 78 79 // Generate random numbers and extract their significands... 80 for ( i = 0; i < 100; i++ ) { 81 frac = randu() * 10.0; 82 exp = round( randu()*44.0 ) - 22; 83 x = frac * pow( 10.0, exp ); 84 x = toFloat32( x ); 85 s = significandf( x ); 86 console.log( 'x: %d. significand: %d.', x, s ); 87 } 88 ``` 89 90 </section> 91 92 <!-- /.examples --> 93 94 <section class="links"> 95 96 [ieee754]: https://en.wikipedia.org/wiki/IEEE_754-1985 97 98 </section> 99 100 <!-- /.links -->