time-to-botec

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

main.js (2110B)


      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 compute = require( './minmaxabs.js' );
     24 
     25 
     26 // MAIN //
     27 
     28 /**
     29 * Returns the minimum and maximum absolute values.
     30 *
     31 * @param {(Array|TypedArray|Object)} [out] - output object
     32 * @param {number} x - first number
     33 * @param {number} [y] - second number
     34 * @param {...number} [args] - numbers
     35 * @returns {(Array|TypedArray|Object)} minimum and maximum absolute values
     36 *
     37 * @example
     38 * var v = minmaxabs( 3.14, 4.2 );
     39 * // returns [ 3.14, 4.2 ]
     40 *
     41 * @example
     42 * var out = [ 0.0, 0.0 ];
     43 * var v = minmaxabs( out, -5.9, 3.14, 4.2 );
     44 * // returns [ 3.14, 5.9 ]
     45 *
     46 * var bool = ( v === out );
     47 * // returns true
     48 *
     49 * @example
     50 * var v = minmaxabs( 3.14, NaN );
     51 * // returns [ NaN, NaN ]
     52 *
     53 * @example
     54 * var v = minmaxabs( +0.0, -0.0 );
     55 * // returns [ 0.0, 0.0 ]
     56 */
     57 function minmaxabs( out, x, y ) {
     58 	var bool;
     59 	var args;
     60 	var len;
     61 	var i;
     62 
     63 	len = arguments.length;
     64 	if ( len === 1 ) {
     65 		return compute( [ 0.0, 0.0 ], out );
     66 	}
     67 	bool = ( typeof arguments[ 0 ] === 'number' );
     68 	if ( len === 2 ) {
     69 		if ( bool ) {
     70 			return compute( [ 0.0, 0.0 ], out, x );
     71 		}
     72 		return compute( out, x );
     73 	}
     74 	if ( len === 3 ) {
     75 		if ( bool ) {
     76 			return compute( [ 0.0, 0.0 ], out, x, y );
     77 		}
     78 		return compute( out, x, y );
     79 	}
     80 	if ( bool ) {
     81 		args = [];
     82 		args.push( [ 0.0, 0.0 ] );
     83 		i = 0;
     84 	} else {
     85 		args = [];
     86 		args.push( arguments[ 0 ] );
     87 		i = 1;
     88 	}
     89 	for ( ; i < len; i++ ) {
     90 		args.push( arguments[ i ] );
     91 	}
     92 	return compute.apply( null, args );
     93 }
     94 
     95 
     96 // EXPORTS //
     97 
     98 module.exports = minmaxabs;