main.js (2044B)
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 fcn = require( './normalize.js' ); 24 25 26 // MAIN // 27 28 /** 29 * Returns a normal number `y` and exponent `exp` satisfying \\(x = y \cdot 2^\mathrm{exp}\\). 30 * 31 * @param {(Array|TypedArray|Object)} [out] - output array 32 * @param {number} x - input value 33 * @returns {(Array|TypedArray|Object)} output array 34 * 35 * @example 36 * var pow = require( '@stdlib/math/base/special/pow' ); 37 * 38 * var out = normalize( [ 0.0, 0 ], 3.14e-319 ); 39 * // returns [ 1.4141234400356668e-303, -52 ] 40 * 41 * var y = out[ 0 ]; 42 * var exp = out[ 1 ]; 43 * 44 * var bool = ( y*pow(2.0,exp) === 3.14e-319 ); 45 * // returns true 46 * 47 * @example 48 * var Float64Array = require( '@stdlib/array/float64' ); 49 * var pow = require( '@stdlib/math/base/special/pow' ); 50 * 51 * var out = new Float64Array( 2 ); 52 * 53 * var v = normalize( out, 3.14e-319 ); 54 * // returns <Float64Array>[ 1.4141234400356668e-303, -52 ] 55 * 56 * var bool = ( v === out ); 57 * // returns true 58 * 59 * @example 60 * var out = normalize( [ 0.0, 0 ], 0.0 ); 61 * // returns [ 0.0, 0 ] 62 * 63 * @example 64 * var out = normalize( [ 0.0, 0 ], Infinity ); 65 * // returns [ Infinity, 0 ] 66 * 67 * @example 68 * var out = normalize( [ 0.0, 0 ], -Infinity ); 69 * // returns [ -Infinity, 0 ] 70 * 71 * @example 72 * var out = normalize( [ 0.0, 0 ], NaN ); 73 * // returns [ NaN, 0 ] 74 */ 75 function normalize( out, x ) { 76 if ( arguments.length === 1 ) { 77 return fcn( [ 0.0, 0 ], out ); 78 } 79 return fcn( out, x ); 80 } 81 82 83 // EXPORTS // 84 85 module.exports = normalize;