index.js (1727B)
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 /** 22 * Return a normal number `y` and exponent `exp` satisfying \\(x = y \cdot 2^\mathrm{exp}\\). 23 * 24 * @module @stdlib/number/float32/base/normalize 25 * 26 * @example 27 * var pow = require( '@stdlib/math/base/special/pow' ); 28 * var toFloat32 = require( '@stdlib/number/float64/base/to-float32' ); 29 * var normalizef = require( '@stdlib/number/float32/base/normalize' ); 30 * 31 * var out = normalizef( toFloat32( 1.401e-45 ) ); 32 * // returns [ 1.1754943508222875e-38, -23 ] 33 * 34 * var y = out[ 0 ]; 35 * var exp = out[ 1 ]; 36 * 37 * var bool = ( y*pow(2,exp) === toFloat32(1.401e-45) ); 38 * // returns true 39 * 40 * @example 41 * var Float32Array = require( '@stdlib/array/float32' ); 42 * var toFloat32 = require( '@stdlib/number/float64/base/to-float32' ); 43 * var normalizef = require( '@stdlib/number/float32/base/normalize' ); 44 * 45 * var out = new Float32Array( 2 ); 46 * 47 * var v = normalizef( out, toFloat32( 1.401e-45 ) ); 48 * // returns <Float32Array>[ 1.1754943508222875e-38, -23.0 ] 49 * 50 * var bool = ( v === out ); 51 * // returns true 52 */ 53 54 // MODULES // 55 56 var normalizef = require( './main.js' ); 57 58 59 // EXPORTS // 60 61 module.exports = normalizef;