time-to-botec

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

README.md (2072B)


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