time-to-botec

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

README.md (3875B)


      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 # fromWordf
     22 
     23 > Create a [single-precision floating-point number][ieee754] from an unsigned integer corresponding to an [IEEE 754][ieee754] binary representation.
     24 
     25 <section class="usage">
     26 
     27 ## Usage
     28 
     29 ```javascript
     30 var fromWordf = require( '@stdlib/number/float32/base/from-word' );
     31 ```
     32 
     33 #### fromWordf( word )
     34 
     35 Creates a [single-precision floating-point number][ieee754] from an unsigned `integer` corresponding to an [IEEE 754][ieee754] binary representation.
     36 
     37 ```javascript
     38 var word = 1068180177; // => 0 01111111 01010110010001011010001
     39 
     40 var f32 = fromWordf( word ); // when printed, implicitly promoted to float64
     41 // returns 1.3370000123977661
     42 ```
     43 
     44 </section>
     45 
     46 <!-- /.usage -->
     47 
     48 <section class="notes">
     49 
     50 ## Notes
     51 
     52 -   The equivalent of this function in C/C++,
     53 
     54     ```c
     55     float fromWordf(unsigned int x) {
     56       return *(float*)&x;
     57     }
     58     ```
     59 
     60 </section>
     61 
     62 <!-- /.notes -->
     63 
     64 <section class="examples">
     65 
     66 ## Examples
     67 
     68 <!-- eslint no-undef: "error" -->
     69 
     70 ```javascript
     71 var randu = require( '@stdlib/random/base/randu' );
     72 var round = require( '@stdlib/math/base/special/round' );
     73 var MAX_UINT32 = require( '@stdlib/constants/uint32/max' );
     74 var fromWordf = require( '@stdlib/number/float32/base/from-word' );
     75 
     76 var word;
     77 var f32;
     78 var i;
     79 
     80 // Create single-precision floating-point numbers from unsigned integers...
     81 for ( i = 0; i < 1000; i++ ) {
     82     word = round( randu()*MAX_UINT32 );
     83     f32 = fromWordf( word );
     84     console.log( 'word: %d => float32: %d', word, f32 );
     85 }
     86 ```
     87 
     88 </section>
     89 
     90 <!-- /.examples -->
     91 
     92 <!-- C interface documentation. -->
     93 
     94 * * *
     95 
     96 <section class="c">
     97 
     98 ## C APIs
     99 
    100 <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
    101 
    102 <section class="intro">
    103 
    104 </section>
    105 
    106 <!-- /.intro -->
    107 
    108 <!-- C usage documentation. -->
    109 
    110 <section class="usage">
    111 
    112 ### Usage
    113 
    114 ```c
    115 #include "stdlib/number/float32/base/from_word.h"
    116 ```
    117 
    118 #### stdlib_base_float32_from_word( word, \*x )
    119 
    120 Creates a [single-precision floating-point number][ieee754] from an unsigned 32-bit integer corresponding to an [IEEE 754][ieee754] binary representation.
    121 
    122 ```c
    123 #include <stdint.h>
    124 
    125 uint32_t word = 1078523331;
    126 
    127 float x;
    128 stdlib_base_float32_from_word( word, &x );
    129 ```
    130 
    131 The function accepts the following arguments:
    132 
    133 -   **word**: `[in] uint32_t` input word.
    134 -   **x**: `[out] float*` destination for a single-precision floating-point number.
    135 
    136 ```c
    137 void stdlib_base_float32_from_word( const uint32_t word, float *x );
    138 ```
    139 
    140 </section>
    141 
    142 <!-- /.usage -->
    143 
    144 <!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
    145 
    146 <section class="notes">
    147 
    148 </section>
    149 
    150 <!-- /.notes -->
    151 
    152 <!-- C API usage examples. -->
    153 
    154 <section class="examples">
    155 
    156 ### Examples
    157 
    158 ```c
    159 #include "stdlib/number/float32/base/from_word.h"
    160 #include <stdint.h>
    161 #include <stdio.h>
    162 
    163 int main() {
    164     uint32_t word = 1078523331;
    165 
    166     float x;
    167     int i;
    168     for ( i = 0; i < 10; i++ ) {
    169         stdlib_base_float32_from_word( word+(uint32_t)(i*10), &x );
    170         printf( "word: %u => %f\n", word, x );
    171     }
    172 }
    173 ```
    174 
    175 </section>
    176 
    177 <!-- /.examples -->
    178 
    179 </section>
    180 
    181 <!-- /.c -->
    182 
    183 <section class="links">
    184 
    185 [ieee754]: https://en.wikipedia.org/wiki/IEEE_754-1985
    186 
    187 </section>
    188 
    189 <!-- /.links -->