time-to-botec

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

main.js (3170B)


      1 /**
      2 * @license Apache-2.0
      3 *
      4 * Copyright (c) 2018 The Stdlib Authors.
      5 *
      6 * Licensed under the Apache License, Version 2.0 (the "License");
      7 * you may not use this file except in compliance with the License.
      8 * You may obtain a copy of the License at
      9 *
     10 *    http://www.apache.org/licenses/LICENSE-2.0
     11 *
     12 * Unless required by applicable law or agreed to in writing, software
     13 * distributed under the License is distributed on an "AS IS" BASIS,
     14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     15 * See the License for the specific language governing permissions and
     16 * limitations under the License.
     17 */
     18 
     19 'use strict';
     20 
     21 // MODULES //
     22 
     23 var Uint32Array = require( '@stdlib/array/uint32' );
     24 var Float64Array = require( '@stdlib/array/float64' );
     25 var LOW = require( './low.js' );
     26 
     27 
     28 // VARIABLES //
     29 
     30 var FLOAT64_VIEW = new Float64Array( 1 );
     31 var UINT32_VIEW = new Uint32Array( FLOAT64_VIEW.buffer );
     32 
     33 
     34 // MAIN //
     35 
     36 /**
     37 * Sets the less significant 32 bits of a double-precision floating-point number.
     38 *
     39 * ## Notes
     40 *
     41 * ```text
     42 * float64 (64 bits)
     43 * f := fraction (significand/mantissa) (52 bits)
     44 * e := exponent (11 bits)
     45 * s := sign bit (1 bit)
     46 *
     47 * |-------- -------- -------- -------- -------- -------- -------- --------|
     48 * |                                Float64                                |
     49 * |-------- -------- -------- -------- -------- -------- -------- --------|
     50 * |              Uint32               |               Uint32              |
     51 * |-------- -------- -------- -------- -------- -------- -------- --------|
     52 * ```
     53 *
     54 * If little endian (more significant bits last):
     55 *
     56 * ```text
     57 *                         <-- lower      higher -->
     58 * |   f7       f6       f5       f4       f3       f2    e2 | f1 |s|  e1  |
     59 * ```
     60 *
     61 * If big endian (more significant bits first):
     62 *
     63 * ```text
     64 *                         <-- higher      lower -->
     65 * |s| e1    e2 | f1     f2       f3       f4       f5        f6      f7   |
     66 * ```
     67 *
     68 * In which Uint32 can we find the lower order bits? If little endian, the first; if big endian, the second.
     69 *
     70 *
     71 * ## References
     72 *
     73 * -   [Open Group][1]
     74 *
     75 * [1]: http://pubs.opengroup.org/onlinepubs/9629399/chap14.htm
     76 *
     77 * @param {number} x - double
     78 * @param {uinteger32} low - unsigned 32-bit integer to replace the lower order word of `x`
     79 * @returns {number} double having the same higher order word as `x`
     80 *
     81 * @example
     82 * var low = 5 >>> 0; // => 00000000000000000000000000000101
     83 *
     84 * var x = 3.14e201; // => 0 11010011100 01001000001011000011 10010011110010110101100010000010
     85 *
     86 * var y = setLowWord( x, low ); // => 0 11010011100 01001000001011000011 00000000000000000000000000000101
     87 * // returns 3.139998651394392e+201
     88 *
     89 * @example
     90 * var PINF = require( '@stdlib/constants/float64/pinf' );
     91 * var NINF = require( '@stdlib/constants/float64/ninf' );
     92 *
     93 * var low = 12345678;
     94 *
     95 * var y = setLowWord( PINF, low );
     96 * // returns NaN
     97 *
     98 * y = setLowWord( NINF, low );
     99 * // returns NaN
    100 *
    101 * y = setLowWord( NaN, low );
    102 * // returns NaN
    103 */
    104 function setLowWord( x, low ) {
    105 	FLOAT64_VIEW[ 0 ] = x;
    106 	UINT32_VIEW[ LOW ] = ( low >>> 0 ); // identity bit shift to ensure integer
    107 	return FLOAT64_VIEW[ 0 ];
    108 }
    109 
    110 
    111 // EXPORTS //
    112 
    113 module.exports = setLowWord;