1// Copyright JS Foundation and other contributors, http://js.foundation 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15var nan = NaN; 16var p_zero = 0.0; 17var m_zero = -p_zero; 18var p_inf = Infinity; 19var m_inf = -p_inf; 20 21assert (isNaN(Math['round'](NaN))); 22assert (Math['round'](p_zero) === p_zero); 23assert (Math['round'](m_zero) === m_zero); 24assert (Math['round'](p_inf) === p_inf); 25assert (Math['round'](m_inf) === m_inf); 26 27assert (Math['round'](0.5) === 1.0); 28assert (Math['round'](-0.5) === -0.0); 29assert (Math['round'](1.2) === 1.0); 30assert (Math['round'](1.5) === 2.0); 31assert (Math['round'](0.7) === 1.0); 32assert (Math['round'](0.2) === 0.0); 33assert (Math['round'](-0.2) === -0.0); 34assert (Math['round'](-0.7) === -1.0); 35assert (Math['round'](-1.2) === -1.0); 36assert (Math['round'](-1.7) === -2.0); 37assert (Math['round'](-1.5) === -1.0); 38 39assert (Math['round'](1) === 1); 40assert (Math['round'](-1) === -1); 41 42for (var n = 1; n <= 53; n++) 43{ 44 var x = Math.pow(2, n) 45 assert (Math['round'](x - 1) === x - 1); 46 assert (Math['round'](x) === x); 47 assert (Math['round'](x + 1) === x + 1); 48 assert (Math['round'](-x - 1) === -x - 1); 49 assert (Math['round'](-x) === -x); 50 assert (Math['round'](-x + 1) === -x + 1); 51} 52