main.js (2522B)
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 HIGH = require( './high.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 * Returns an unsigned 32-bit integer corresponding to the more 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 higher order bits? If little endian, the second; if big endian, the first. 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 - input value 78 * @returns {uinteger32} higher order word 79 * 80 * @example 81 * var w = getHighWord( 3.14e201 ); // => 01101001110001001000001011000011 82 * // returns 1774486211 83 */ 84 function getHighWord( x ) { 85 FLOAT64_VIEW[ 0 ] = x; 86 return UINT32_VIEW[ HIGH ]; 87 } 88 89 90 // EXPORTS // 91 92 module.exports = getHighWord;