basics.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. WScript.LoadScriptFile("..\\UnitTestFramework\\UnitTestFramework.js");
  6. function checkNaN(value, message) {
  7. assert.isTrue(isNaN(value), message);
  8. }
  9. function checkNegZero(value, message) {
  10. assert.strictEqual(1/value, -Infinity, message);
  11. }
  12. function checkPlusZero(value, message) {
  13. assert.strictEqual(1/value, +Infinity, message);
  14. }
  15. function checkClose(value, target, message) {
  16. assert.isTrue(Math.abs(value - target) < 0.000000001, message)
  17. }
  18. const tests = [
  19. {
  20. name: "Constants",
  21. body() {
  22. assert.areEqual(Math.E , 2.718281828459045, "Maths constant with wrong value");
  23. assert.areEqual(Math.PI , 3.141592653589793, "Maths constant with wrong value");
  24. assert.areEqual(Math.LN10 , 2.302585092994046, "Maths constant with wrong value");
  25. assert.areEqual(Math.LN2 , 0.6931471805599453, "Maths constant with wrong value");
  26. assert.areEqual(Math.LOG2E , 1.4426950408889633, "Maths constant with wrong value");
  27. assert.areEqual(Math.LOG10E , 0.4342944819032518, "Maths constant with wrong value");
  28. assert.areEqual(Math.SQRT1_2, 0.7071067811865476, "Maths constant with wrong value");
  29. assert.areEqual(Math.SQRT2 , 1.4142135623730951, "Maths constant with wrong value");
  30. }
  31. },
  32. {
  33. name : "Math.abs",
  34. body() {
  35. checkNaN(Math.abs(NaN), "Math.abs(NaN) should equal NaN");
  36. checkNaN(Math.abs(), "Math.abs() should equal NaN");
  37. checkPlusZero(Math.abs(-0), "Math.abs should convert -0 to 0");
  38. checkPlusZero(Math.abs(+0), "Math.abs should convert -0 to 0");
  39. var input = [+Infinity, -Infinity, -3.14, 3.14, -5, 5, 2147483647 /*INT_MAX*/, -2147483648 /* INT_MIN */];
  40. var expected = [+Infinity, +Infinity, 3.14, 3.14, 5, 5, 2147483647, 2147483648];
  41. for (var i in input) {
  42. assert.isFalse(Math.abs(input[i]) !== expected[i], `Math.abs(${input[i]}) should equal ${expected[i]}`);
  43. }
  44. }
  45. },
  46. {
  47. name : "Math.sqrt",
  48. body() {
  49. checkNaN(Math.sqrt(NaN), "Math.sqrt(NaN) should equal NaN");
  50. checkNaN(Math.sqrt(), "Math.sqrt() should equal NaN");
  51. checkNaN(Math.sqrt(-Infinity), "Math.sqrt(-Infinity) should equal NaN");
  52. checkNaN(Math.sqrt(-0.1), "Math.sqrt(-0.1) should equal NaN");
  53. checkPlusZero(Math.sqrt(+0), "Math.sqrt(+0) should be +0");
  54. checkNegZero(Math.sqrt(-0.0), "Math.sqrt(-0) should be -0");
  55. assert.strictEqual(Math.sqrt(+Infinity), +Infinity, "Math.sqrt(+Infinity) should equal +Infinity")
  56. assert.strictEqual(Math.sqrt(25), 5, "Math.sqrt(25) should equal 5")
  57. }
  58. },
  59. {
  60. name : "Math.cos",
  61. body() {
  62. checkNaN(Math.cos(), "Math.cos() should be NaN");
  63. checkNaN(Math.cos(NaN), "Math.cos(NaN) should be NaN");
  64. // infinity
  65. checkNaN(Math.cos(+Infinity), "Math.cos(+Infinity) should be NaN");
  66. checkNaN(Math.cos(-Infinity), "Math.cos(-Infinity) should be NaN");
  67. assert.strictEqual(Math.cos(+0), 1, "Math.cos(+0) should be 1");
  68. assert.strictEqual(Math.cos(-0.0), 1, "Math.cos(-0.0) should be 1");
  69. checkClose(Math.cos((Math.PI) / 2), 0, "Math.cos((Math.PI) / 2) should be 0");
  70. checkClose(Math.cos((Math.PI) / 3), 0.5, "Math.cos((Math.PI) / 3) should be 0.5");
  71. }
  72. },
  73. {
  74. name : "Math.acos",
  75. body() {
  76. checkNaN(Math.acos(), "Math.acos() should be NaN");
  77. checkNaN(Math.acos(NaN), "Math.acos(NaN) should be NaN");
  78. // interesting floating point limits
  79. checkNaN(Math.acos(5.1), "Math.acos(5.1) should be NaN");
  80. checkNaN(Math.acos(-2), "Math.acos(-2) should be NaN");
  81. // infinity
  82. checkNaN(Math.acos(+Infinity), "Math.acos(+Infinity) should be NaN");
  83. checkNaN(Math.acos(-Infinity), "Math.acos(-Infinity) should be NaN");
  84. assert.strictEqual(Math.acos(1), 0, "Math.acos(1) should be 0");
  85. assert.strictEqual(Math.acos(0), (Math.PI) / 2, "Math.acos(0) should be (Math.PI) / 2");
  86. checkClose(Math.acos(0.5), (Math.PI) / 3, "Math.acos(0.5) should be (Math.PI) / 3");
  87. }
  88. },
  89. {
  90. name : "Math.sin",
  91. body() {
  92. checkNaN(Math.sin(), "Math.sin() should be NaN");
  93. checkNaN(Math.sin(NaN), "Math.sin(NaN) should be NaN");
  94. // infinity
  95. checkNaN(Math.sin(+Infinity), "Math.sin(+Infinity) should be NaN");
  96. checkNaN(Math.sin(-Infinity), "Math.sin(-Infinity) should be NaN");
  97. // +0 and -0
  98. checkPlusZero(Math.sin(+0.0), "Math.sin(+0.0) should be +0");
  99. checkNegZero(Math.sin(-0.0), "Math.sin(-0.0) should be -0");
  100. assert.strictEqual(Math.sin(Math.PI / 2), 1, "Math.sin(Math.PI / 2) should be 1");
  101. checkClose(Math.sin(Math.PI / 6), 0.5, "Math.sin(Math.PI / 6) should be 0.5");
  102. }
  103. },
  104. {
  105. name : "Math.asin",
  106. body() {
  107. checkNaN(Math.asin(), "Math.asin() should be NaN");
  108. checkNaN(Math.asin(NaN), "Math.asin(NaN) should be NaN");
  109. // interesting floating point limits
  110. checkNaN(Math.asin(5.1), "Math.asin(5.1) should be NaN");
  111. checkNaN(Math.asin(-2), "Math.asin(-2) should be NaN");
  112. // infinity
  113. checkNaN(Math.asin(+Infinity), "Math.asin(+Infinity) should be NaN");
  114. checkNaN(Math.asin(-Infinity), "Math.asin(-Infinity) should be NaN");
  115. assert.strictEqual(Math.asin(1), (Math.PI) / 2, "Math.asin(1) should be (Math.PI) / 2");
  116. checkClose(Math.asin(0.5), (Math.PI) / 6, "Math.asin(0.5) should be (Math.PI) / 6");
  117. checkPlusZero(Math.asin(+0), "Math.asin(+0) should be +0");
  118. checkNegZero(Math.asin(-0.0), "Math.asin(-0.0) should be -0");
  119. }
  120. },
  121. {
  122. name : "Math.atan",
  123. body() {
  124. checkNaN(Math.atan(), "Math.atan() should be NaN");
  125. checkNaN(Math.atan(NaN), "Math.atan(NaN) should be NaN");
  126. assert.strictEqual(Math.atan(+Infinity), (Math.PI) / 2, "Math.atan(+Infinity) should be (Math.PI) / 2");
  127. assert.strictEqual(Math.atan(-Infinity), -(Math.PI) / 2, "Math.atan(-Infinity) should be -(Math.PI) / 2");
  128. assert.strictEqual(Math.atan(1), (Math.PI) / 4, "Math.atan(1) should be (Math.PI) / 4");
  129. checkPlusZero(Math.atan(+0), "Math.atan(+0) should be +0");
  130. checkNegZero(Math.atan(-0.0), "Math.atan(-0.0) should be -0");
  131. }
  132. },
  133. {
  134. name : "Math.tan",
  135. body() {
  136. checkNaN(Math.tan(), "Math.tan() should be NaN");
  137. checkNaN(Math.tan(NaN), "Math.tan(NaN) should be NaN");
  138. // infinity
  139. checkNaN(Math.tan(+Infinity), "Math.tan(+Infinity) should be NaN");
  140. checkNaN(Math.tan(-Infinity), "Math.tan(-Infinity) should be NaN");
  141. // +0 and -0
  142. checkPlusZero(Math.tan(+0), "Math.tan(+0) should be +0");
  143. checkNegZero(Math.tan(-0.0), "Math.tan(-0.0) should be -0");
  144. checkClose(Math.tan(Math.PI / 4), 1, "Math.tan(Math.PI / 4) should be 1");
  145. }
  146. },
  147. {
  148. name : "Math.exp",
  149. body() {
  150. checkNaN(Math.exp(), "Math.exp() should be NaN");
  151. checkNaN(Math.exp(NaN), "Math.exp(NaN) should be NaN");
  152. assert.strictEqual(Math.exp(+0), 1, "Math.exp(1) should be 1");
  153. assert.strictEqual(Math.exp(-0.0), 1, "Math.exp(-0.0) should be 1");
  154. assert.strictEqual(Math.exp(+Infinity), +Infinity, "Math.exp(+Infinity) should be +Infinity");
  155. assert.strictEqual(Math.exp(-Infinity), 0, "Math.exp(-Infinity) should be 0");
  156. checkClose(Math.exp(3), Math.E * Math.E * Math.E, "Math.exp(3) should be Math.E * Math.E * Math.E");
  157. }
  158. },
  159. {
  160. name : "Math.log",
  161. body() {
  162. checkNaN(Math.log(), "Math.log() should be NaN");
  163. checkNaN(Math.log(NaN), "Math.log(NaN) should be NaN");
  164. assert.strictEqual(Math.log(+0), -Infinity, "Math.log(+0) should be -Infinity");
  165. assert.strictEqual(Math.log(-0.0), -Infinity, "Math.log(-0.0) should be -Infinity");
  166. assert.strictEqual(Math.log(1), 0, "Math.log(1) should be 0");
  167. assert.strictEqual(Math.log(+Infinity), +Infinity, "Math.log(+Infinity) should be +Infinity");
  168. assert.strictEqual(Math.log(Math.E*Math.E*Math.E), 3, "Math.log(Math.E*Math.E*Math.E) should be 3");
  169. }
  170. },
  171. {
  172. name : "Math.pow",
  173. body() {
  174. function checkNaNPow(x, y) {
  175. checkNaN(Math.pow(x, y), `Math.pow(${x}, ${y}) should be NaN`);
  176. }
  177. function check(result, x, y) {
  178. var pow = Math.pow(x, y);
  179. if (result !== 0) {
  180. if (pow !== result) {
  181. checkClose(pow, result, `Math.pow(${x}, ${y}) should equal ${result}`);
  182. }
  183. } else if (1 / result === +Infinity) {
  184. checkPlusZero(pow, `Math.pow(${x}, ${y}) should equal +0`);
  185. } else {
  186. checkNegZero(pow, `Math.pow(${x}, ${y}) should equal -0`);
  187. }
  188. }
  189. checkNaN(Math.pow(), "Math.pow() should be NaN");
  190. checkNaNPow(NaN, NaN);
  191. checkNaNPow(Infinity, NaN);
  192. checkNaNPow(-Infinity, NaN);
  193. checkNaNPow(0, NaN);
  194. checkNaNPow(-0, NaN);
  195. checkNaNPow(3, NaN);
  196. checkNaNPow(-3, NaN);
  197. check(1, NaN, 0);
  198. check(1, Infinity, 0);
  199. check(1, -Infinity, 0);
  200. check(1, 0, 0);
  201. check(1, -0, 0);
  202. check(1, 3, 0);
  203. check(1, -3, 0);
  204. check(1, NaN, -0);
  205. check(1, Infinity, -0);
  206. check(1, -Infinity, -0);
  207. check(1, 0, -0);
  208. check(1, -0, -0);
  209. check(1, 3, -0);
  210. check(1, -3, -0);
  211. checkNaNPow(NaN, 3);
  212. checkNaNPow(NaN, Infinity);
  213. checkNaNPow(NaN, -Infinity);
  214. check(Infinity, +1.1, Infinity);
  215. check(Infinity, -1.1, Infinity);
  216. check(0, +1.1, -Infinity);
  217. check(0, -1.1, -Infinity);
  218. checkNaNPow(+1, Infinity);
  219. checkNaNPow(-1, Infinity);
  220. checkNaNPow(+1, -Infinity);
  221. checkNaNPow(-1, -Infinity);
  222. check(0, +0.9, Infinity);
  223. check(0, -0.9, Infinity);
  224. check(Infinity, +0.9, -Infinity);
  225. check(Infinity, -0.9, -Infinity);
  226. check(Infinity, Infinity, 0.1);
  227. check(+0, Infinity, -0.1);
  228. check(-Infinity, -Infinity, 3);
  229. check(+Infinity, -Infinity, 4);
  230. check(-0, -Infinity, -3);
  231. check(+0, -Infinity, -4);
  232. check(0, 0, 0.1);
  233. check(+Infinity, +0, -3);
  234. check(+Infinity, +0, -0.1);
  235. check(+Infinity, -0, -1.1);
  236. check(-0.0, -0, +3);
  237. check(+0.0, -0, +4);
  238. check(-Infinity, -0, -3);
  239. check(+Infinity, -0, -4);
  240. checkNaNPow(-3, 3.3);
  241. check(25, 5, 2);
  242. check(25, -5, 2);
  243. check(1/25, -5, -2);
  244. }
  245. },
  246. {
  247. name : "Math.atan2",
  248. body() {
  249. checkNaN(Math.atan2(), "Math.atan2() should be NaN");
  250. checkNaN(Math.atan2(NaN, NaN), "Math.atan2(NaN, NaN) should be NaN");
  251. checkNaN(Math.atan2(2, NaN), "Math.atan2(2, NaN) should be NaN");
  252. checkNaN(Math.atan2(NaN, -3), "Math.atan2(NaN, -3) should be NaN");
  253. function checkATan2(result, a, b) {
  254. assert.strictEqual(Math.atan2(a, b), result, `Math.atan2(${a}, ${b}) should equal ${result}`);
  255. }
  256. checkATan2((Math.PI) / 2, 3, +0);
  257. checkATan2((Math.PI) / 2, 3, -0);
  258. checkPlusZero(Math.atan2(0, 3),"Math.atan2(0, 3) should equal +0");
  259. checkPlusZero(Math.atan2(0, 0),"Math.atan2(0, 0) should equal +0");
  260. checkATan2(Math.PI, 0, -0);
  261. checkATan2(Math.PI, 0, -2);
  262. checkNegZero(Math.atan2(-0, 3),"Math.atan2(-0, 3) should equal -0");
  263. checkNegZero(Math.atan2(-0, 0),"Math.atan2(-0, 0) should equal -0");
  264. checkATan2(-Math.PI, -0, -0);
  265. checkATan2(-Math.PI, -0, -2);
  266. checkATan2(-(Math.PI) / 2, -3, +0);
  267. checkATan2(-(Math.PI) / 2, -3, -0);
  268. checkPlusZero(Math.atan2(3, +Infinity),"Math.atan2(3, +Infinity) should equal +0");
  269. checkATan2((Math.PI), 3, -Infinity);
  270. checkATan2((-Math.PI), -3, -Infinity);
  271. checkNegZero(Math.atan2(-3, +Infinity),"Math.atan2(-3, +Infinity) should equal -0");
  272. checkATan2((Math.PI)/2, +Infinity, 3);
  273. checkATan2(-(Math.PI) / 2, -Infinity, 3);
  274. checkATan2((Math.PI) / 2, +Infinity, -3);
  275. checkATan2(-(Math.PI) / 2, -Infinity, -3);
  276. checkATan2(Math.PI / 4, +Infinity, +Infinity);
  277. checkATan2(3 * Math.PI / 4, +Infinity, -Infinity);
  278. checkATan2(-Math.PI / 4, -Infinity, +Infinity);
  279. checkATan2(-3 * Math.PI / 4, -Infinity, -Infinity);
  280. checkATan2((Math.PI) / 4, 5, 5.0);
  281. }
  282. },
  283. {
  284. name: "Math.ceil and Math.floor",
  285. body() {
  286. checkNaN(Math.ceil(NaN), "Math.ceil(NaN) should be NaN");
  287. checkNaN(Math.ceil(), "Math.ceil() should be NaN");
  288. checkNaN(Math.floor(NaN), "Math.floor(NaN) should be NaN");
  289. checkNaN(Math.floor(), "Math.floor() should be NaN");
  290. function check(result, value) {
  291. var ceil = Math.ceil(value);
  292. var floor = Math.floor(-value);
  293. if (result !== 0) {
  294. assert.strictEqual(ceil, result, `Math.ceil(${value}) should equal ${result} not ${ceil}`);
  295. assert.strictEqual(-floor, result, `-Math.floor(${-value}) should equal ${result} not ${-floor}`);
  296. } else if (1/result === -Infinity || (value > -1 && value < 1 && value !== 0)) {
  297. checkNegZero(ceil, `Math.ceil(${value}) should equal -0 not ${ceil}`);
  298. checkPlusZero(floor, `Math.floor(${-value}) should equal +0 not ${floor}`)
  299. } else {
  300. checkPlusZero(ceil, `Math.ceil(${value}) should equal +0 not ${ceil}`);
  301. checkNegZero(floor, `Math.floor(${-value}) should equal -0 not ${floor}`)
  302. }
  303. }
  304. check(+0, +0);
  305. check(-0, -0);
  306. check(+Infinity, +Infinity);
  307. check(-Infinity, -Infinity);
  308. // values abs(x) < 1
  309. check(-0, -4.9406564584124654000e-324);
  310. check(-0, -9.8813129168249309000e-324);
  311. check(-0, -0.5);
  312. check(-0, -9.9999999999999989000e-001);
  313. check(-0, -9.9999999999999978000e-001);
  314. check(-1, -1);
  315. check(1, 4.9406564584124654000e-324);
  316. check(1, 9.8813129168249309000e-324);
  317. check(1, 0.5);
  318. check(1, 9.9999999999999989000e-001);
  319. check(1, 9.9999999999999978000e-001);
  320. check(1, 1);
  321. // other interesting double values
  322. var x = 1;
  323. for(var i = 0; i < 50; ++i)
  324. {
  325. check(x, x - 0.1);
  326. check(-x + 1, -x + 0.1);
  327. x = x * 2;
  328. }
  329. check(54, 53.7);
  330. check(112233581321, 112233581320.001);
  331. // values around the maximums
  332. check(1.7976931348623157000e+308, 1.7976931348623157000e+308);
  333. check(-1.7976931348623157000e+308, -1.7976931348623157000e+308)
  334. // values around INT_MIN and INT_MAX for amd64 (Bug 179932)
  335. assert.isFalse(Math.ceil(2147483648) <= 2147483647, "Math.ceil(2147483648) should not be <= 2147483647");
  336. assert.isFalse(Math.ceil(-2147483649) >= -2147483648, "Math.ceil(-2147483649) should not be >= -2147483648");
  337. check(-0, -0.1);
  338. check(-0, -0);
  339. }
  340. },
  341. {
  342. name : "Math.round",
  343. body() {
  344. // check rounding of NaN
  345. checkNaN(Math.round(NaN), "Math.round(NaN) should be NaN");
  346. checkNaN(Math.round(Math.asin(2.0)), "Math.round(Math.asin(2.0)) should be NaN");
  347. checkNaN(Math.round(), "Math.round() should be NaN");
  348. // check rounding of Infinity
  349. assert.strictEqual(Infinity, Math.round(Infinity), "Math.round(Infinity)");
  350. assert.strictEqual(-Infinity, Math.round(-Infinity), "Math.round(-Infinity)");
  351. // check positive and negative 0
  352. checkPlusZero(Math.round(+0), "Math.round(+0)");
  353. checkNegZero(Math.round(-0), "Math.round(-0)");
  354. // check various values between 0 and 0.5
  355. checkPlusZero(Math.round(4.9999999999999994000e-001), "round largest value < 0.5"); // for ES5 the result is 0
  356. checkPlusZero(Math.round(4.9999999999999989000e-001), "round 2nd largest value < 0.5");
  357. checkPlusZero(Math.round(4.9406564584124654000e-324), "round smallest value > 0");
  358. checkPlusZero(Math.round(9.8813129168249309000e-324), "round 2nd smallest value > 0");
  359. for(var i = 0.001; i < 0.5; i += 0.001)
  360. {
  361. checkPlusZero(Math.round(i), "round " + i);
  362. }
  363. // check various values between -0.5 and 0
  364. checkNegZero(Math.round(-4.9406564584124654000e-324), "round most positive value < 0");
  365. checkNegZero(Math.round(-9.8813129168249309000e-324), "round 2nd most positive value < 0");
  366. checkNegZero(Math.round(-4.9999999999999994000e-001), "round most negative value > -0.5");
  367. checkNegZero(Math.round(-4.9999999999999989000e-001), "round 2nd most negative value > -0.5");
  368. checkNegZero(Math.round(-0), "round -0 should be -0");
  369. for(var i = -0.001; i > -0.5; i -= 0.001)
  370. {
  371. checkNegZero(Math.round(i), "round " + i);
  372. }
  373. // check various integers
  374. assert.strictEqual(1, Math.round(1), "round 1");
  375. assert.strictEqual(2, Math.round(2), "round 2");
  376. assert.strictEqual(-1, Math.round(-1), "round -1");
  377. assert.strictEqual(-2, Math.round(-2), "round -2");
  378. assert.strictEqual(4294967295, Math.round(4294967295), "round 4294967295");
  379. assert.strictEqual(4294967296, Math.round(4294967296), "round 4294967296");
  380. assert.strictEqual(-4294967296, Math.round(-4294967296), "round -4294967296");
  381. for(var i = 1000; i < 398519; i += 179)
  382. {
  383. assert.strictEqual(i, Math.round(i), "round " + i);
  384. }
  385. for(var i = 0.001; i <= 0.5; i += 0.001)
  386. {
  387. assert.strictEqual(1, Math.round(0.5 + i), "round " + (0.5+i));
  388. }
  389. for(var i = -0.001; i >= -0.5; i -= 0.001)
  390. {
  391. assert.strictEqual(-1, Math.round(-0.5 + i), "round " + (-0.5+i));
  392. }
  393. // check I + 0.5
  394. assert.strictEqual(1, Math.round(0.5), "round 0.5");
  395. assert.strictEqual(2, Math.round(1.5), "round 1.5");
  396. assert.strictEqual(3, Math.round(2.5), "round 2.5");
  397. assert.strictEqual(4294967296, Math.round(4294967295 + 0.5), "round 4294967295.5");
  398. for(var i = -100000; i <= 100000; i += 100)
  399. {
  400. assert.strictEqual(i+1, Math.round(i + 0.5), "round " + (i+0.5));
  401. }
  402. // miscellaneous other real numbers
  403. assert.strictEqual(30593859183, Math.round(30593859183.3915898), "round a double with high precision");
  404. assert.strictEqual(1, Math.round(5.0000000000000011000e-001), "round smallest value > 0.5");
  405. assert.strictEqual(1, Math.round(5.0000000000000022000e-001), "round 2nd smallest value > 0.5");
  406. assert.strictEqual(1.7976931348623157000e+308, Math.round(1.7976931348623157000e+308), "round largest number < Infinity");
  407. assert.strictEqual(1.7976931348623155000e+308, Math.round(1.7976931348623155000e+308), "round 2nd largest number < Infinity");
  408. assert.strictEqual(-1.7976931348623157000e+308, Math.round(-1.7976931348623157000e+308), "round least positive number > -Infinity");
  409. assert.strictEqual(-1.7976931348623155000e+308, Math.round(-1.7976931348623155000e+308), "round 2nd least positive number > -Infinity");
  410. // if x <= -2^52 or x >= 2^52, Math.round(x) == x
  411. assert.strictEqual(4503599627370496, Math.round(4503599627370496), "round 4503599627370496");
  412. assert.strictEqual(4503599627370497, Math.round(4503599627370497), "round 4503599627370497");
  413. assert.strictEqual(4503599627370548, Math.round(4503599627370548), "round 4503599627370548");
  414. assert.strictEqual(9007199254740991, Math.round(9007199254740991), "round 9007199254740991");
  415. assert.strictEqual(-4503599627370496, Math.round(-4503599627370496), "round -4503599627370496");
  416. assert.strictEqual(-4503599627370497, Math.round(-4503599627370497), "round -4503599627370497");
  417. assert.strictEqual(-4503599627370548, Math.round(-4503599627370548), "round -4503599627370548");
  418. assert.strictEqual(-9007199254740991, Math.round(-9007199254740991), "round -9007199254740991");
  419. // values around INT_MIN and INT_MAX for amd64 (Bug 179932)
  420. assert.isFalse(Math.round(2147483648) <= 2147483647, "Math.round(2147483648)")
  421. assert.isFalse(Math.round(-2147483649) >= -2147483648, "Math.round(-2147483649)")
  422. }
  423. }
  424. ];
  425. testRunner.runTests(tests, { verbose: WScript.Arguments[0] != "summary" });