round.js (1526B)
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 // TODO: implementation 22 23 /** 24 * Rounds a numeric value to the nearest integer. 25 * 26 * @param {number} x - input value 27 * @returns {number} function value 28 * 29 * @example 30 * var v = round( -4.2 ); 31 * // returns -4.0 32 * 33 * @example 34 * var v = round( -4.5 ); 35 * // returns -4.0 36 * 37 * @example 38 * var v = round( -4.6 ); 39 * // returns -5.0 40 * 41 * @example 42 * var v = round( 9.99999 ); 43 * // returns 10.0 44 * 45 * @example 46 * var v = round( 9.5 ); 47 * // returns 10.0 48 * 49 * @example 50 * var v = round( 9.2 ); 51 * // returns 9.0 52 * 53 * @example 54 * var v = round( 0.0 ); 55 * // returns 0.0 56 * 57 * @example 58 * var v = round( -0.0 ); 59 * // returns -0.0 60 * 61 * @example 62 * var v = round( Infinity ); 63 * // returns Infinity 64 * 65 * @example 66 * var v = round( -Infinity ); 67 * // returns -Infinity 68 * 69 * @example 70 * var v = round( NaN ); 71 * // returns NaN 72 */ 73 var round = Math.round; // eslint-disable-line stdlib/no-builtin-math 74 75 76 // EXPORTS // 77 78 module.exports = round;