time-to-botec

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

README.md (4287B)


      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 # From Words
     22 
     23 > Create a [double-precision floating-point number][ieee754] from a higher order word and a lower order word.
     24 
     25 <section class="usage">
     26 
     27 ## Usage
     28 
     29 ```javascript
     30 var fromWords = require( '@stdlib/number/float64/base/from-words' );
     31 ```
     32 
     33 #### fromWords( high, low )
     34 
     35 Creates a [double-precision floating-point number][ieee754] from a higher order word (unsigned 32-bit `integer`) and a lower order word (unsigned 32-bit `integer`).
     36 
     37 ```javascript
     38 var v = fromWords( 1774486211, 2479577218 );
     39 // returns 3.14e201
     40 
     41 v = fromWords( 3221823995, 1413754136 );
     42 // returns -3.141592653589793
     43 
     44 v = fromWords( 0, 0 );
     45 // returns 0.0
     46 
     47 v = fromWords( 2147483648, 0 );
     48 // returns -0.0
     49 
     50 v = fromWords( 2146959360, 0 );
     51 // returns NaN
     52 
     53 v = fromWords( 2146435072, 0 );
     54 // returns Infinity
     55 
     56 v = fromWords( 4293918720, 0 );
     57 // returns -Infinity
     58 ```
     59 
     60 </section>
     61 
     62 <!-- /.usage -->
     63 
     64 <section class="notes">
     65 
     66 ## Notes
     67 
     68 -   For more information regarding higher and lower order words, see [to-words][@stdlib/number/float64/base/to-words].
     69 
     70 </section>
     71 
     72 <!-- /.notes -->
     73 
     74 <section class="examples">
     75 
     76 ## Examples
     77 
     78 <!-- eslint no-undef: "error" -->
     79 
     80 ```javascript
     81 var randu = require( '@stdlib/random/base/randu' );
     82 var round = require( '@stdlib/math/base/special/round' );
     83 var MAX_UINT32 = require( '@stdlib/constants/uint32/max' );
     84 var fromWords = require( '@stdlib/number/float64/base/from-words' );
     85 
     86 var high;
     87 var low;
     88 var x;
     89 var i;
     90 
     91 for ( i = 0; i < 100; i++ ) {
     92     high = round( randu()*MAX_UINT32 );
     93     low = round( randu()*MAX_UINT32 );
     94     x = fromWords( high, low );
     95     console.log( 'higher: %d. lower: %d. float: %d.', high, low, x );
     96 }
     97 ```
     98 
     99 </section>
    100 
    101 <!-- /.examples -->
    102 
    103 <!-- C interface documentation. -->
    104 
    105 * * *
    106 
    107 <section class="c">
    108 
    109 ## C APIs
    110 
    111 <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
    112 
    113 <section class="intro">
    114 
    115 </section>
    116 
    117 <!-- /.intro -->
    118 
    119 <!-- C usage documentation. -->
    120 
    121 <section class="usage">
    122 
    123 ### Usage
    124 
    125 ```c
    126 #include "stdlib/number/float64/base/from_words.h"
    127 ```
    128 
    129 #### stdlib_base_float64_from_words( high, low, \*x )
    130 
    131 Creates a double-precision floating-point number from a higher order word and a lower order word.
    132 
    133 ```c
    134 #include <stdint.h>
    135 
    136 uint32_t high = 1074339512;
    137 uint32_t low = 1374389535;
    138 
    139 double x;
    140 stdlib_base_float64_from_words( high, low, &x );
    141 ```
    142 
    143 The function accepts the following arguments:
    144 
    145 -   **high**: `[in] uint32_t` higher order word.
    146 -   **low**: `[in] uint32_t` lower order word.
    147 -   **x**: `[out] double*` destination for a double-precision floating-point number.
    148 
    149 ```c
    150 void stdlib_base_float64_from_words( const uint32_t high, const uint32_t low, double *x );
    151 ```
    152 
    153 </section>
    154 
    155 <!-- /.usage -->
    156 
    157 <!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
    158 
    159 <section class="notes">
    160 
    161 </section>
    162 
    163 <!-- /.notes -->
    164 
    165 <!-- C API usage examples. -->
    166 
    167 <section class="examples">
    168 
    169 ### Examples
    170 
    171 ```c
    172 #include "stdlib/number/float64/base/from_words.h"
    173 #include <stdint.h>
    174 #include <stdio.h>
    175 
    176 int main() {
    177     uint32_t high = 1074339512;
    178     uint32_t low[] = { 0, 10000, 1000000, 1374389535 };
    179 
    180     double x;
    181     int i;
    182     for ( i = 0; i < 4; i++ ) {
    183         stdlib_base_float64_from_words( high, low[ i ], &x );
    184         printf( "high: %u, low: %u => %lf\n", high, low[ i ], x );
    185     }
    186 }
    187 ```
    188 
    189 </section>
    190 
    191 <!-- /.examples -->
    192 
    193 </section>
    194 
    195 <!-- /.c -->
    196 
    197 <section class="links">
    198 
    199 [ieee754]: https://en.wikipedia.org/wiki/IEEE_754-1985
    200 
    201 [@stdlib/number/float64/base/to-words]: https://www.npmjs.com/package/@stdlib/number/tree/main/float64/base/to-words
    202 
    203 </section>
    204 
    205 <!-- /.links -->