time-to-botec

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

main.js (2082B)


      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 normalize = 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 - single-precision floating-point number
     33 * @returns {(Array|TypedArray|Object)} output array
     34 *
     35 * @example
     36 * var toFloat32 = require( '@stdlib/number/float64/base/to-float32' );
     37 *
     38 * var v = normalizef( toFloat32( 1.401e-45 ) );
     39 * // returns [ 1.1754943508222875e-38, -23 ]
     40 *
     41 * @example
     42 * var Float32Array = require( '@stdlib/array/float32' );
     43 * var toFloat32 = require( '@stdlib/number/float64/base/to-float32' );
     44 *
     45 * var out = new Float32Array( 2 );
     46 *
     47 * var v = normalizef( out, toFloat32( 1.401e-45 ) );
     48 * // returns <Float32Array>[ 1.1754943508222875e-38, -23 ]
     49 *
     50 * var bool = ( v === out );
     51 * // returns true
     52 *
     53 * @example
     54 * var v = normalizef( 0.0 );
     55 * // returns [ 0.0, 0 ]
     56 *
     57 * @example
     58 * var PINF = require( '@stdlib/constants/float32/pinf' );
     59 *
     60 * var v = normalizef( PINF );
     61 * // returns [ +Infinity, 0 ]
     62 *
     63 * @example
     64 * var NINF = require( '@stdlib/constants/float32/ninf' );
     65 *
     66 * var v = normalizef( NINF );
     67 * // returns [ -Infinity, 0 ]
     68 *
     69 * @example
     70 * var v = normalizef( NaN );
     71 * // returns [ NaN, 0 ]
     72 */
     73 function normalizef( out, x ) {
     74 	if ( arguments.length === 1 ) {
     75 		return normalize( [ 0.0, 0 ], out );
     76 	}
     77 	return normalize( out, x );
     78 }
     79 
     80 
     81 // EXPORTS //
     82 
     83 module.exports = normalizef;