min.js (1190B)
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 // MAIN // 22 23 /** 24 * Returns the minimum value. 25 * 26 * @param {number} x - first number 27 * @param {number} y - second number 28 * @returns {number} minimum value 29 * 30 * @example 31 * var v = min( 3.14, 4.2 ); 32 * // returns 3.14 33 * 34 * @example 35 * var v = min( 3.14, NaN ); 36 * // returns NaN 37 * 38 * @example 39 * var v = min( NaN, 3.14 ); 40 * // returns 3.14 41 * 42 * @example 43 * var v = min( -0.0, +0.0 ); 44 * // returns +0.0 45 * 46 * @example 47 * var v = min( +0.0, -0.0 ); 48 * // returns -0.0 49 */ 50 function min( x, y ) { 51 if ( x < y ) { 52 return x; 53 } 54 return y; 55 } 56 57 58 // EXPORTS // 59 60 module.exports = min;