time-to-botec

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

README.md (4468B)


      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 # Set High Word
     22 
     23 > Set the more significant 32 bits of a [double-precision floating-point number][ieee754].
     24 
     25 <section class="usage">
     26 
     27 ## Usage
     28 
     29 ```javascript
     30 var setHighWord = require( '@stdlib/number/float64/base/set-high-word' );
     31 ```
     32 
     33 #### setHighWord( x, high )
     34 
     35 Sets the more significant 32 bits (higher order word) of a [double-precision floating-point number][ieee754] `x` to a bit sequence represented by an unsigned 32-bit integer `high`. The returned `double` will have the same less significant 32 bits (lower order word) as `x`.
     36 
     37 ```javascript
     38 var high = 5 >>> 0; // => 0 00000000000 00000000000000000101
     39 
     40 var y = setHighWord( 3.14e201, high ); // => 0 00000000000 0000000000000000010110010011110010110101100010000010
     41 // returns 1.18350528745e-313
     42 
     43 var PINF = require( '@stdlib/constants/float64/pinf' ); // => 0 11111111111 00000000000000000000 00000000000000000000000000000000
     44 
     45 high = 1072693248 >>> 0; // => 0 01111111111 00000000000000000000
     46 
     47 // Set the higher order bits of `+infinity` to return `1`:
     48 y = setHighWord( PINF, high ); // => 0 01111111111 0000000000000000000000000000000000000000000000000000
     49 // returns 1.0
     50 ```
     51 
     52 </section>
     53 
     54 <!-- /.usage -->
     55 
     56 <section class="examples">
     57 
     58 ## Examples
     59 
     60 <!-- eslint no-undef: "error" -->
     61 
     62 ```javascript
     63 var pow = require( '@stdlib/math/base/special/pow' );
     64 var round = require( '@stdlib/math/base/special/round' );
     65 var randu = require( '@stdlib/random/base/randu' );
     66 var MAX_UINT32 = require( '@stdlib/constants/uint32/max' );
     67 var setHighWord = require( '@stdlib/number/float64/base/set-high-word' );
     68 
     69 var high;
     70 var frac;
     71 var exp;
     72 var x;
     73 var y;
     74 var i;
     75 
     76 // Generate a random double-precision floating-point number:
     77 frac = randu() * 10.0;
     78 exp = -round( randu() * 323.0 );
     79 x = frac * pow( 10.0, exp );
     80 
     81 // Replace the higher order word of `x` to generate new random numbers having the same lower order word...
     82 for ( i = 0; i < 100; i++ ) {
     83     high = round( randu()*MAX_UINT32 );
     84     y = setHighWord( x, high );
     85     console.log( 'x: %d. new high word: %d. y: %d.', x, high, y );
     86 }
     87 ```
     88 
     89 </section>
     90 
     91 <!-- /.examples -->
     92 
     93 <!-- C interface documentation. -->
     94 
     95 * * *
     96 
     97 <section class="c">
     98 
     99 ## C APIs
    100 
    101 <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
    102 
    103 <section class="intro">
    104 
    105 </section>
    106 
    107 <!-- /.intro -->
    108 
    109 <!-- C usage documentation. -->
    110 
    111 <section class="usage">
    112 
    113 ### Usage
    114 
    115 ```c
    116 #include "stdlib/number/float64/base/set_high_word.h"
    117 ```
    118 
    119 #### stdlib_base_float64_set_high_word( high, \*x )
    120 
    121 Sets the more significant 32 bits of a double-precision floating-point number.
    122 
    123 ```c
    124 #include <stdint.h>
    125 
    126 uint32_t high = 1074339512;
    127 double x = 0.0;
    128 
    129 stdlib_base_float64_set_high_word( high, &x );
    130 ```
    131 
    132 The function accepts the following arguments:
    133 
    134 -   **high**: `[in] uint32_t` higher order word.
    135 -   **x**: `[in-out] double*` reference to (and destination for) a double-precision floating-point number.
    136 
    137 ```c
    138 void stdlib_base_float64_set_high_word( const uint32_t high, double *x );
    139 ```
    140 
    141 </section>
    142 
    143 <!-- /.usage -->
    144 
    145 <!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
    146 
    147 <section class="notes">
    148 
    149 </section>
    150 
    151 <!-- /.notes -->
    152 
    153 <!-- C API usage examples. -->
    154 
    155 <section class="examples">
    156 
    157 ### Examples
    158 
    159 ```c
    160 #include "stdlib/number/float64/base/set_high_word.h"
    161 #include <stdint.h>
    162 #include <stdio.h>
    163 
    164 int main() {
    165     uint32_t high[] = { 1074339512, 1074339513, 1074339514, 1074339515 };
    166     double x = 3.14;
    167 
    168     int i;
    169     for ( i = 0; i < 4; i++ ) {
    170         stdlib_base_float64_set_high_word( high[ i ], &x );
    171         printf( "high: %u => %lf\n", high[ i ], x );
    172     }
    173 }
    174 ```
    175 
    176 </section>
    177 
    178 <!-- /.examples -->
    179 
    180 </section>
    181 
    182 <!-- /.c -->
    183 
    184 <section class="links">
    185 
    186 [ieee754]: https://en.wikipedia.org/wiki/IEEE_754-1985
    187 
    188 </section>
    189 
    190 <!-- /.links -->