closure1a.js (1412B)
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 * Returns a function to compute the hypotenuse using the alpha max plus beta min algorithm. 23 * 24 * @private 25 * @param {number} alpha - alpha 26 * @param {number} beta - beta 27 * @returns {Function} function to compute the hypotenuse 28 * 29 * @example 30 * var fcn = wrap( 1.0, 0.5 ); 31 * // returns <Function> 32 */ 33 function wrap( alpha, beta ) { 34 return hypot; 35 36 /** 37 * Computes the hypotenuse using the alpha max plus beta min algorithm. 38 * 39 * @private 40 * @param {NonNegativeNumber} x - number 41 * @param {NonNegativeNumber} y - number 42 * @returns {number} hypotenuse 43 * 44 * @example 45 * var h = hypot( 5.0, 12.0 ); 46 * // returns <number> 47 */ 48 function hypot( x, y ) { 49 if ( x > y ) { 50 return (alpha*x) + (beta*y); 51 } 52 return (beta*x) + (alpha*y); 53 } 54 } 55 56 57 // EXPORTS // 58 59 module.exports = wrap;