# Number Precision in test262

a guest
Mar 9th, 2012
241
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. /** sections of test262 that cover number precision
2.
3.     "S11": "5.1.A4: T1-T8",
4.     "S15": {
5.         "7": "3: 2.A1 & 3.A1",
6.         "8": {
7.             "1": "1-8: A1",
8.             "2": {
9.                 "4": "A4 & A5",
10.                 "5": "A: 3,6,7,10-13,15,17-19",
11.                 "7": "A6 & A7",
12.                 "13": "A24",
13.                 "16": "A6 & A7",
14.                 "17": "A6",
15.                 "18": "A6"
16.             }
17.         }
18.     },
19.     "S8": "5.A2: 1 & 2"
20.
21.
22. SOURCES OF SAID SECTIONS: (in no specific order)
23. **/
24.
26. // This code is governed by the BSD license found in the LICENSE file.
27.
28. /**
29.  * The result of a floating-point multiplication is governed by the rules of IEEE 754 double-precision arithmetics
30.  *
31.  * @path ch11/11.5/11.5.1/S11.5.1_A4_T1.1.js
32.  * @description If left operand is NaN, the result is NaN
33.  */
34.
35. //CHECK#1
36. if (isNaN(Number.NaN * Number.NaN) !== true) {
37.   \$ERROR('#1: NaN * NaN === Not-a-Number. Actual: ' + (NaN * NaN));
38. }
39.
40. //CHECK#2
41. if (isNaN(Number.NaN * +0) !== true) {
42.   \$ERROR('#2: NaN * +0 === Not-a-Number. Actual: ' + (NaN * +0));
43. }
44.
45. //CHECK#3
46. if (isNaN(Number.NaN * -0) !== true) {
47.   \$ERROR('#3: NaN * -0 === Not-a-Number. Actual: ' + (NaN * -0));
48. }
49.
50. //CHECK#4
51. if (isNaN(Number.NaN * Number.POSITIVE_INFINITY) !== true) {
52.   \$ERROR('#4: NaN * Infinity === Not-a-Number. Actual: ' + (NaN * Infinity));
53. }
54.
55. //CHECK#5
56. if (isNaN(Number.NaN * Number.NEGATIVE_INFINITY) !== true) {
57.   \$ERROR('#5: NaN * -Infinity === Not-a-Number. Actual: ' + (NaN * -Infinity));
58. }
59.
60. //CHECK#6
61. if (isNaN(Number.NaN * Number.MAX_VALUE) !== true) {
62.   \$ERROR('#6: NaN * Number.MAX_VALUE === Not-a-Number. Actual: ' + (NaN * Number.MAX_VALUE));
63. }
64.
65. //CHECK#7
66. if (isNaN(Number.NaN * Number.MIN_VALUE) !== true) {
67.   \$ERROR('#7: NaN * Number.MIN_VALUE === Not-a-Number. Actual: ' + (NaN * Number.MIN_VALUE));
68. }
69.
70. //CHECK#8
71. if (isNaN(Number.NaN * 1) !== true) {
72.   \$ERROR('#8: NaN * 1 === Not-a-Number. Actual: ' + (NaN * 1));
73. }
74.
76. // This code is governed by the BSD license found in the LICENSE file.
77.
78. /**
79.  * The result of a floating-point multiplication is governed by the rules of IEEE 754 double-precision arithmetics
80.  *
81.  * @path ch11/11.5/11.5.1/S11.5.1_A4_T1.2.js
82.  * @description If right operand is NaN, the result is NaN
83.  */
84.
85. //CHECK#1
86. if (isNaN(Number.NaN * Number.NaN) !== true) {
87.   \$ERROR('#1: NaN * NaN === Not-a-Number. Actual: ' + (NaN * NaN));
88. }
89.
90. //CHECK#2
91. if (isNaN(+0 * Number.NaN) !== true) {
92.   \$ERROR('#2: +0 * NaN === Not-a-Number. Actual: ' + (+0 * NaN));
93. }
94.
95. //CHECK#3
96. if (isNaN(-0 * Number.NaN) !== true) {
97.   \$ERROR('#3: -0 * NaN === Not-a-Number. Actual: ' + (-0 * NaN));
98. }
99.
100. //CHECK#4
101. if (isNaN(Number.POSITIVE_INFINITY * Number.NaN) !== true) {
102.   \$ERROR('#4: Infinity * NaN === Not-a-Number. Actual: ' + (Infinity * NaN));
103. }
104.
105. //CHECK#5
106. if (isNaN(Number.NEGATIVE_INFINITY * Number.NaN) !== true) {
107.   \$ERROR('#5:  -Infinity * NaN === Not-a-Number. Actual: ' + ( -Infinity * NaN));
108. }
109.
110. //CHECK#6
111. if (isNaN(Number.MAX_VALUE * Number.NaN) !== true) {
112.   \$ERROR('#6: Number.MAX_VALUE * NaN === Not-a-Number. Actual: ' + (Number.MAX_VALUE * NaN));
113. }
114.
115. //CHECK#7
116. if (isNaN(Number.MIN_VALUE * Number.NaN) !== true) {
117.   \$ERROR('#7: Number.MIN_VALUE * NaN === Not-a-Number. Actual: ' + (Number.MIN_VALUE * NaN));
118. }
119.
120. //CHECK#8
121. if (isNaN(1 * Number.NaN) !== true) {
122.   \$ERROR('#8: 1 * NaN === Not-a-Number. Actual: ' + (1 * NaN));
123. }
124.
126. // This code is governed by the BSD license found in the LICENSE file.
127.
128. /**
129.  * The result of a floating-point multiplication is governed by the rules of IEEE 754 double-precision arithmetics
130.  *
131.  * @path ch11/11.5/11.5.1/S11.5.1_A4_T2.js
132.  * @description The sign of the result is positive if both operands have the same sign, negative if the operands have different signs
133.  */
134.
135. //CHECK#1
136. if (1 * 1 !== 1) {
137.   \$ERROR('#1: 1 * 1 === 1. Actual: ' + (1 * 1));
138. }
139.
140. //CHECK#2
141. if (1 * -1 !== -1) {
142.   \$ERROR('#2: 1 * -1 === -1. Actual: ' + (1 * -1));
143. }
144.
145. //CHECK#3
146. if (-1 * 1 !== -1) {
147.   \$ERROR('#3: -1 * 1 === -1. Actual: ' + (-1 * 1));
148. }
149.
150. //CHECK#4
151. if (-1 * -1 !== 1) {
152.   \$ERROR('#4: -1 * -1 === 1. Actual: ' + (-1 * -1));
153. }
154.
155. //CHECK#5
156. if (0 * 0 !== 0) {
157.   \$ERROR('#5.1: 0 * 0 === 0. Actual: ' + (0 * 0));
158. } else {
159.   if (1 / (0 * 0) !== Number.POSITIVE_INFINITY) {
160.     \$ERROR('#5.2: 0 * 0 === + 0. Actual: -0');
161.   }
162. }
163.
164. //CHECK#6
165. if (0 * -0 !== -0) {
166.   \$ERROR('#6.1: 0 * -0 === 0. Actual: ' + (0 * -0));
167. } else {
168.   if (1 / (0 * -0) !== Number.NEGATIVE_INFINITY) {
169.     \$ERROR('#6.2: 0 * -0 === - 0. Actual: +0');
170.   }
171. }
172.
173. //CHECK#7
174. if (-0 * 0 !== -0) {
175.   \$ERROR('#7.1: -0 * 0 === 0. Actual: ' + (-0 * 0));
176. } else {
177.   if (1 / (-0 * 0) !== Number.NEGATIVE_INFINITY) {
178.     \$ERROR('#7.2: -0 * 0 === - 0. Actual: +0');
179.   }
180. }
181.
182. //CHECK#8
183. if (-0 * -0 !== 0) {
184.   \$ERROR('#8.1: -0 * -0 === 0. Actual: ' + (-0 * -0));
185. } else {
186.   if (1 / (-0 * -0) !== Number.POSITIVE_INFINITY) {
187.     \$ERROR('#8.2: 0 * -0 === - 0. Actual: +0');
188.   }
189. }
190.
192. // This code is governed by the BSD license found in the LICENSE file.
193.
194. /**
195.  * The result of a floating-point multiplication is governed by the rules of IEEE 754 double-precision arithmetics
196.  *
197.  * @path ch11/11.5/11.5.1/S11.5.1_A4_T3.js
198.  * @description Multiplication of an infinity by a zero results in NaN
199.  */
200.
201. //CHECK#1
202. if (isNaN(Number.NEGATIVE_INFINITY * 0) !== true) {
203.   \$ERROR('#1: Infinity * 0 === Not-a-Number. Actual: ' + (Infinity * 0));
204. }
205.
206. //CHECK#2
207. if (isNaN(-0 * Number.NEGATIVE_INFINITY) !== true) {
208.   \$ERROR('#2: -0 * -Infinity === Not-a-Number. Actual: ' + (-0 * -Infinity));
209. }
210.
211. //CHECK#3
212. if (isNaN(Number.POSITIVE_INFINITY * -0) !== true) {
213.   \$ERROR('#3: Infinity * -0 === Not-a-Number. Actual: ' + (Infinity * -0));
214. }
215.
216. //CHECK#4
217. if (isNaN(0 * Number.POSITIVE_INFINITY) !== true) {
218.   \$ERROR('#4: 0 * Infinity === Not-a-Number. Actual: ' + (0 * Infinity));
219. }
220.
221. //CHECK#5
222. if (isNaN(Number.NEGATIVE_INFINITY * -0) !== true) {
223.   \$ERROR('#5: Infinity * -0 === Not-a-Number. Actual: ' + (Infinity * -0));
224. }
225.
226. //CHECK#6
227. if (isNaN(0 * Number.NEGATIVE_INFINITY) !== true) {
228.   \$ERROR('#6: 0 * -Infinity === Not-a-Number. Actual: ' + (0 * -Infinity));
229. }
230.
231. //CHECK#7
232. if (isNaN(Number.POSITIVE_INFINITY * 0) !== true) {
233.   \$ERROR('#7: Infinity * 0 === Not-a-Number. Actual: ' + (Infinity * 0));
234. }
235.
236. //CHECK#8
237. if (isNaN(-0 * Number.POSITIVE_INFINITY) !== true) {
238.   \$ERROR('#8: -0 * Infinity === Not-a-Number. Actual: ' + (-0 * Infinity));
239. }
240.
242. // This code is governed by the BSD license found in the LICENSE file.
243.
244. /**
245.  * The result of a floating-point multiplication is governed by the rules of IEEE 754 double-precision arithmetics
246.  *
247.  * @path ch11/11.5/11.5.1/S11.5.1_A4_T4.js
248.  * @description Multiplication of an infinity by an infinity results in an infinity of appropriate sign
249.  */
250.
251. //CHECK#1
252. if (Number.NEGATIVE_INFINITY * Number.NEGATIVE_INFINITY !== Number.POSITIVE_INFINITY) {
253.   \$ERROR('#1: -Infinity * -Infinity === Infinity. Actual: ' + (-Infinity * -Infinity));
254. }
255.
256. //CHECK#2
257. if (Number.POSITIVE_INFINITY * Number.POSITIVE_INFINITY !== Number.POSITIVE_INFINITY) {
258.   \$ERROR('#2: Infinity * Infinity === Infinity. Actual: ' + (Infinity * Infinity));
259. }
260.
261. //CHECK#3
262. if (Number.NEGATIVE_INFINITY * Number.POSITIVE_INFINITY !== Number.NEGATIVE_INFINITY) {
263.   \$ERROR('#3: -Infinity * Infinity === -Infinity. Actual: ' + (-Infinity * Infinity));
264. }
265.
266. //CHECK#4
267. if (Number.POSITIVE_INFINITY * Number.NEGATIVE_INFINITY !== Number.NEGATIVE_INFINITY) {
268.   \$ERROR('#4: Infinity * -Infinity === -Infinity. Actual: ' + (Infinity * -Infinity));
269. }
270.
272. // This code is governed by the BSD license found in the LICENSE file.
273.
274. /**
275.  * The result of a floating-point multiplication is governed by the rules of IEEE 754 double-precision arithmetics
276.  *
277.  * @path ch11/11.5/11.5.1/S11.5.1_A4_T5.js
278.  * @description Multiplication of an infinity by a finite non-zero value results in a signed infinity
279.  */
280.
281. //CHECK#1
282. if (Number.NEGATIVE_INFINITY * -1 !== Number.POSITIVE_INFINITY) {
283.   \$ERROR('#1: -Infinity * -1 === Infinity. Actual: ' + (-Infinity * -1));
284. }
285.
286. //CHECK#2
287. if (-1 * Number.NEGATIVE_INFINITY !== Number.POSITIVE_INFINITY) {
288.   \$ERROR('#2: -1 * -Infinity === Infinity. Actual: ' + (-1 * -Infinity));
289. }
290.
291. //CHECK#3
292. if (Number.POSITIVE_INFINITY * -1 !== Number.NEGATIVE_INFINITY) {
293.   \$ERROR('#3: Infinity * -1 === -Infinity. Actual: ' + (Infinity * -1));
294. }
295.
296. //CHECK#4
297. if (-1 * Number.POSITIVE_INFINITY !== Number.NEGATIVE_INFINITY) {
298.   \$ERROR('#4: -1 * Infinity === -Infinity. Actual: ' + (-1 * Infinity));
299. }
300.
301. //CHECK#5
302. if (Number.POSITIVE_INFINITY * Number.MAX_VALUE !== Number.POSITIVE_INFINITY) {
303.   \$ERROR('#5: Infinity * Number.MAX_VALUE === Infinity. Actual: ' + (Infinity * Number.MAX_VALUE));
304. }
305.
306. //CHECK#6
307. if (Number.POSITIVE_INFINITY * Number.MAX_VALUE !== Number.MAX_VALUE * Number.POSITIVE_INFINITY) {
308.   \$ERROR('#6: Infinity * Number.MAX_VALUE === Number.MAX_VALUE * Infinity. Actual: ' + (Infinity * Number.MAX_VALUE));
309. }
310.
311. //CHECK#7
312. if (Number.NEGATIVE_INFINITY * Number.MIN_VALUE !== Number.NEGATIVE_INFINITY) {
313.   \$ERROR('#7: -Infinity * Number.MIN_VALUE === -Infinity. Actual: ' + (-Infinity * Number.MIN_VALUE));
314. }
315.
316. //CHECK#8
317. if (Number.NEGATIVE_INFINITY * Number.MIN_VALUE !== Number.MIN_VALUE * Number.NEGATIVE_INFINITY) {
318.   \$ERROR('#8: -Infinity * Number.MIN_VALUE === Number.MIN_VALUE * -Infinity. Actual: ' + (-Infinity * Number.MIN_VALUE));
319. }
320.
322. // This code is governed by the BSD license found in the LICENSE file.
323.
324. /**
325.  * The result of a floating-point multiplication is governed by the rules of IEEE 754 double-precision arithmetics
326.  *
327.  * @path ch11/11.5/11.5.1/S11.5.1_A4_T6.js
328.  * @description If the magnitude is too large to represent, the result is then an infinity of appropriate sign
329.  */
330.
331. //CHECK#1
332. if (Number.MAX_VALUE * 1.1 !== Number.POSITIVE_INFINITY) {
333.   \$ERROR('#1: Number.MAX_VALUE * 1.1 === Number.POSITIVE_INFINITY. Actual: ' + (Number.MAX_VALUE * 1.1));
334. }
335.
336. //CHECK#2
337. if (-1.1 * Number.MAX_VALUE !== Number.NEGATIVE_INFINITY) {
338.   \$ERROR('#2: -1.1 * Number.MAX_VALUE === Number.NEGATIVE_INFINITY. Actual: ' + (-1.1 * Number.MAX_VALUE));
339. }
340.
341. //CHECK#3
342. if (Number.MAX_VALUE * 1 !== Number.MAX_VALUE) {
343.   \$ERROR('#3: Number.MAX_VALUE * 1 === Number.MAX_VALUE. Actual: ' + (Number.MAX_VALUE * 1));
344. }
345.
346. //CHECK#4
347. if (-1 * Number.MAX_VALUE !== -Number.MAX_VALUE) {
348.   \$ERROR('#4: -1 * Number.MAX_VALUE === -Number.MAX_VALUE. Actual: ' + (-1 * Number.MAX_VALUE));
349. }
350.
352. // This code is governed by the BSD license found in the LICENSE file.
353.
354. /**
355.  * The result of a floating-point multiplication is governed by the rules of IEEE 754 double-precision arithmetics
356.  *
357.  * @path ch11/11.5/11.5.1/S11.5.1_A4_T7.js
358.  * @description If the magnitude is too small to represent, the result is then a zero of appropriate sign
359.  */
360.
361. //CHECK#1
362. if (Number.MIN_VALUE * 0.1 !== 0) {
363.   \$ERROR('#1: Number.MIN_VALUE * 0.1 === 0. Actual: ' + (Number.MIN_VALUE * 0.1));
364. }
365.
366. //CHECK#2
367. if (-0.1 * Number.MIN_VALUE !== -0) {
368.   \$ERROR('#2.1: -0.1 * Number.MIN_VALUE === -0. Actual: ' + (-0.1 * Number.MIN_VALUE));
369. } else {
370.   if (1 / (-0.1 * Number.MIN_VALUE) !== Number.NEGATIVE_INFINITY) {
371.     \$ERROR('#2.2: -0.1 * Number.MIN_VALUE === -0. Actual: +0');
372.   }
373. }
374.
375. //CHECK#3
376. if (Number.MIN_VALUE * 0.5 !== 0) {
377.   \$ERROR('#3: Number.MIN_VALUE * 0.5 === 0. Actual: ' + (Number.MIN_VALUE * 0.5));
378. }
379.
380. //CHECK#4
381. if (-0.5 * Number.MIN_VALUE !== -0) {
382.   \$ERROR('#4.1: -0.5 * Number.MIN_VALUE === -0. Actual: ' + (-0.5 * Number.MIN_VALUE));
383. } else {
384.   if (1 / (-0.5 * Number.MIN_VALUE) !== Number.NEGATIVE_INFINITY) {
385.     \$ERROR('#4.2: -0.5 * Number.MIN_VALUE === -0. Actual: +0');
386.   }
387. }
388.
389. //CHECK#5
390. if (Number.MIN_VALUE * 0.51 !== Number.MIN_VALUE) {
391.   \$ERROR('#5: Number.MIN_VALUE * 0.51 === Number.MIN_VALUE. Actual: ' + (Number.MIN_VALUE * 0.51));
392. }
393.
394. //CHECK#6
395. if (-0.51 * Number.MIN_VALUE !== -Number.MIN_VALUE) {
396.   \$ERROR('#6: -0.51 * Number.MIN_VALUE === -Number.MIN_VALUE. Actual: ' + (-0.51 * Number.MIN_VALUE));
397. }
398.
399. //CHECK#7
400. if (Number.MIN_VALUE * 0.9 !== Number.MIN_VALUE) {
401.   \$ERROR('#7: Number.MIN_VALUE * 0.9 === Number.MIN_VALUE. Actual: ' + (Number.MIN_VALUE * 0.9));
402. }
403.
404. //CHECK#8
405. if (-0.9 * Number.MIN_VALUE !== -Number.MIN_VALUE) {
406.   \$ERROR('#8: -0.9 * Number.MIN_VALUE === -Number.MIN_VALUE. Actual: ' + (-0.9 * Number.MIN_VALUE));
407. }
408.
410. // This code is governed by the BSD license found in the LICENSE file.
411.
412. /**
413.  * The result of a floating-point multiplication is governed by the rules of IEEE 754 double-precision arithmetics
414.  *
415.  * @path ch11/11.5/11.5.1/S11.5.1_A4_T8.js
416.  * @description Multiplication is not always associative (x * y * z is the same as (x * y) * z, not x * (y * z))
417.  */
418.
419. //CHECK#1
420. if (Number.MAX_VALUE * 1.1 * 0.9 !== (Number.MAX_VALUE * 1.1) * 0.9) {
421.   \$ERROR('#1: Number.MAX_VALUE * 1.1 * 0.9 === (Number.MAX_VALUE * 1.1) * 0.9. Actual: ' + (Number.MAX_VALUE * 1.1 * 0.9));
422. }
423.
424. //CHECK#2
425. if ((Number.MAX_VALUE * 1.1) * 0.9 === Number.MAX_VALUE * (1.1 * 0.9)) {
426.   \$ERROR('#2: (Number.MAX_VALUE * 1.1) * 0.9 !== Number.MAX_VALUE * (1.1 * 0.9)');
427. }
428.
430. // This code is governed by the BSD license found in the LICENSE file.
431.
432. /**
433.  * Number.MAX_VALUE is approximately 1.7976931348623157e308
434.  *
435.  * @path ch15/15.7/15.7.3/15.7.3.2/S15.7.3.2_A1.js
436.  * @description Checking Number.MAX_VALUE value
437.  */
438.
439. \$INCLUDE("math_precision.js");
440. \$INCLUDE("math_isequal.js");
441.
442. // CHECK#1
443. if (!isEqual(Number.MAX_VALUE, 1.7976931348623157e308)) {
444.   \$ERROR('#1: Number.MAX_VALUE approximately equal to 1.7976931348623157e308');
445. }
446.
448. // This code is governed by the BSD license found in the LICENSE file.
449.
450. /**
451.  * Number.MIN_VALUE is approximately 5e-324
452.  *
453.  * @path ch15/15.7/15.7.3/15.7.3.3/S15.7.3.3_A1.js
454.  * @description Checking Number.MIN_VALUE value
455.  */
456.
457. \$INCLUDE("math_precision.js");
458. \$INCLUDE("math_isequal.js");
459.
460. // CHECK#1
461. if (!isEqual(Number.MIN_VALUE, 5e-324)) {
462.   \$ERROR('#1: Number.MIN_VALUE approximately equal to 5e-324');
463. }
464.
466. // This code is governed by the BSD license found in the LICENSE file.
467.
468. /**
469.  * Math.E is approximately 2.7182818284590452354
470.  *
471.  * @path ch15/15.8/15.8.1/15.8.1.1/S15.8.1.1_A1.js
472.  * @description Comparing Math.E with 2.7182818284590452354
473.  */
474.
475. \$INCLUDE("math_precision.js");
476. \$INCLUDE("math_isequal.js");
477.
478. // CHECK#1
479. if (!isEqual(Math.E, 2.7182818284590452354)) {
480.   \$ERROR('#1: \'Math.E is not approximately equal to 2.7182818284590452354\'');
481. }
482.
484. // This code is governed by the BSD license found in the LICENSE file.
485.
486. /**
487.  * Math.LN10 is approximately 2.302585092994046
488.  *
489.  * @path ch15/15.8/15.8.1/15.8.1.2/S15.8.1.2_A1.js
490.  * @description Comparing Math.LN10 with 2.302585092994046
491.  */
492.
493. \$INCLUDE("math_precision.js");
494. \$INCLUDE("math_isequal.js");
495.
496. // CHECK#1
497. if (!isEqual(Math.LN10, 2.302585092994046)) {
498.   \$ERROR('#1: \'Math.LN10 is not approximately equal to 2.302585092994046\'');
499. }
500.
502. // This code is governed by the BSD license found in the LICENSE file.
503.
504. /**
505.  * Math.LN2 is approximately 0.6931471805599453
506.  *
507.  * @path ch15/15.8/15.8.1/15.8.1.3/S15.8.1.3_A1.js
508.  * @description Comparing Math.LN2 with 0.6931471805599453
509.  */
510.
511. \$INCLUDE("math_precision.js");
512. \$INCLUDE("math_isequal.js");
513.
514. // CHECK#1
515. if (!isEqual(Math.LN2, 0.6931471805599453)) {
516.   \$ERROR('#1: \'Math.LN2 is not approximately equal to 0.6931471805599453\'');
517. }
518.
520. // This code is governed by the BSD license found in the LICENSE file.
521.
522. /**
523.  * Math.LOG2E is approximately 1.4426950408889634
524.  *
525.  * @path ch15/15.8/15.8.1/15.8.1.4/S15.8.1.4_A1.js
526.  * @description Comparing Math.LOG2E with 1.4426950408889634
527.  */
528.
529. \$INCLUDE("math_precision.js");
530. \$INCLUDE("math_isequal.js");
531.
532. // CHECK#1
533. if (!isEqual(Math.LOG2E, 1.4426950408889634)) {
534.   \$ERROR('#1: \'Math.LOG2E is not approximatley equal to 1.4426950408889634\'');
535. }
536.
538. // This code is governed by the BSD license found in the LICENSE file.
539.
540. /**
541.  * Math.LOG10E is approximately 0.4342944819032518
542.  *
543.  * @path ch15/15.8/15.8.1/15.8.1.5/S15.8.1.5_A1.js
544.  * @description Comparing Math.LOG10E with 0.4342944819032518
545.  */
546.
547. \$INCLUDE("math_precision.js");
548. \$INCLUDE("math_isequal.js");
549.
550. // CHECK#1
551. if (!isEqual(Math.LOG10E, 0.4342944819032518)) {
552.   \$ERROR('#1: \'Math.LOG10E is not approximatley equal to  0.4342944819032518\'');
553. }
554.
556. // This code is governed by the BSD license found in the LICENSE file.
557.
558. /**
559.  * Math.PI is approximately 3.1415926535897932
560.  *
561.  * @path ch15/15.8/15.8.1/15.8.1.6/S15.8.1.6_A1.js
562.  * @description Comparing Math.PI with 3.1415926535897932
563.  */
564.
565. \$INCLUDE("math_precision.js");
566. \$INCLUDE("math_isequal.js");
567.
568. // CHECK#1
569. if (!isEqual(Math.PI, 3.1415926535897932)) {
570.   \$ERROR('#1: \'Math.PI is not approximatley equal to 3.1415926535897932\'');
571. }
572.
573.
575. // This code is governed by the BSD license found in the LICENSE file.
576.
577. /**
578.  * Math.SQRT1_2 is approximately 0.7071067811865476
579.  *
580.  * @path ch15/15.8/15.8.1/15.8.1.7/S15.8.1.7_A1.js
581.  * @description Comparing Math.SQRT1_2 with 0.7071067811865476
582.  */
583.
584. \$INCLUDE("math_precision.js");
585. \$INCLUDE("math_isequal.js");
586.
587. // CHECK#1
588. if (!isEqual(Math.SQRT1_2, 0.7071067811865476)) {
589.   \$ERROR('#1: \'Math.SQRT1_2 is not approximatley equal to  0.7071067811865476\'');
590. }
591.
592.
594. // This code is governed by the BSD license found in the LICENSE file.
595.
596. /**
597.  * Math.SQRT2 is approximately 1.4142135623730951
598.  *
599.  * @path ch15/15.8/15.8.1/15.8.1.8/S15.8.1.8_A1.js
600.  * @description Comparing Math.SQRT2 with 1.4142135623730951
601.  */
602.
603. \$INCLUDE("math_precision.js");
604. \$INCLUDE("math_isequal.js");
605.
606. // CHECK#1
607. if (!isEqual(Math.SQRT2, 1.4142135623730951)) {
608.   \$ERROR('#1: \'Math.SQRT2 is not approximatley equal to 1.4142135623730951\'');
609. }
610.
611.
613. // This code is governed by the BSD license found in the LICENSE file.
614.
615. /**
616.  * Math.pow, recommended that implementations use the approximation algorithms for IEEE 754 arithmetic contained in fdlibm
617.  *
618.  * @path ch15/15.8/15.8.2/15.8.2.13/S15.8.2.13_A24.js
619.  * @description Checking if Math.pow(argument1, argument2) is approximately equals to its mathematical value on the set of 64 argument1 values and 64 argument2 values; all the sample values is calculated with LibC
620.  */
621.
622. \$INCLUDE("math_precision.js");
623. \$INCLUDE("math_isequal.js");
624.
625. // CHECK#1
626. vnum = 64;
627. var x1 = new Array();
628. x1[0] = 0.00000000000000000000;
629. x1[1] = 0.25396825396825395000;
630. x1[2] = 0.50793650793650791000;
631. x1[3] = 0.76190476190476186000;
632. x1[4] = 1.01587301587301580000;
633. x1[5] = 1.26984126984126980000;
634. x1[6] = 1.52380952380952370000;
635. x1[7] = 1.77777777777777770000;
636. x1[8] = 2.03174603174603160000;
637. x1[9] = 2.28571428571428560000;
638. x1[10] = 2.53968253968253950000;
639. x1[11] = 2.79365079365079350000;
640. x1[12] = 3.04761904761904740000;
641. x1[13] = 3.30158730158730140000;
642. x1[14] = 3.55555555555555540000;
643. x1[15] = 3.80952380952380930000;
644. x1[16] = 4.06349206349206330000;
645. x1[17] = 4.31746031746031720000;
646. x1[18] = 4.57142857142857120000;
647. x1[19] = 4.82539682539682510000;
648. x1[20] = 5.07936507936507910000;
649. x1[21] = 5.33333333333333300000;
650. x1[22] = 5.58730158730158700000;
651. x1[23] = 5.84126984126984090000;
652. x1[24] = 6.09523809523809490000;
653. x1[25] = 6.34920634920634890000;
654. x1[26] = 6.60317460317460280000;
655. x1[27] = 6.85714285714285680000;
656. x1[28] = 7.11111111111111070000;
657. x1[29] = 7.36507936507936470000;
658. x1[30] = 7.61904761904761860000;
659. x1[31] = 7.87301587301587260000;
660. x1[32] = 8.12698412698412650000;
661. x1[33] = 8.38095238095238140000;
662. x1[34] = 8.63492063492063440000;
663. x1[35] = 8.88888888888888930000;
664. x1[36] = 9.14285714285714230000;
665. x1[37] = 9.39682539682539720000;
666. x1[38] = 9.65079365079365030000;
667. x1[39] = 9.90476190476190510000;
668. x1[40] = 10.15873015873015800000;
669. x1[41] = 10.41269841269841300000;
670. x1[42] = 10.66666666666666600000;
671. x1[43] = 10.92063492063492100000;
672. x1[44] = 11.17460317460317400000;
673. x1[45] = 11.42857142857142900000;
674. x1[46] = 11.68253968253968200000;
675. x1[47] = 11.93650793650793700000;
676. x1[48] = 12.19047619047619000000;
677. x1[49] = 12.44444444444444500000;
678. x1[50] = 12.69841269841269800000;
679. x1[51] = 12.95238095238095300000;
680. x1[52] = 13.20634920634920600000;
681. x1[53] = 13.46031746031746000000;
682. x1[54] = 13.71428571428571400000;
683. x1[55] = 13.96825396825396800000;
684. x1[56] = 14.22222222222222100000;
685. x1[57] = 14.47619047619047600000;
686. x1[58] = 14.73015873015872900000;
687. x1[59] = 14.98412698412698400000;
688. x1[60] = 15.23809523809523700000;
689. x1[61] = 15.49206349206349200000;
690. x1[62] = 15.74603174603174500000;
691. x1[63] = 16.00000000000000000000;
692.
693.
694.
695. var x2 = new Array();
696. x2[0] = -16.00000000000000000000;
697. x2[1] = -15.49206349206349200000;
698. x2[2] = -14.98412698412698400000;
699. x2[3] = -14.47619047619047600000;
700. x2[4] = -13.96825396825396800000;
701. x2[5] = -13.46031746031746000000;
702. x2[6] = -12.95238095238095300000;
703. x2[7] = -12.44444444444444500000;
704. x2[8] = -11.93650793650793700000;
705. x2[9] = -11.42857142857142900000;
706. x2[10] = -10.92063492063492100000;
707. x2[11] = -10.41269841269841300000;
708. x2[12] = -9.90476190476190510000;
709. x2[13] = -9.39682539682539720000;
710. x2[14] = -8.88888888888888930000;
711. x2[15] = -8.38095238095238140000;
712. x2[16] = -7.87301587301587350000;
713. x2[17] = -7.36507936507936560000;
714. x2[18] = -6.85714285714285770000;
715. x2[19] = -6.34920634920634970000;
716. x2[20] = -5.84126984126984180000;
717. x2[21] = -5.33333333333333390000;
718. x2[22] = -4.82539682539682600000;
719. x2[23] = -4.31746031746031810000;
720. x2[24] = -3.80952380952381020000;
721. x2[25] = -3.30158730158730230000;
722. x2[26] = -2.79365079365079440000;
723. x2[27] = -2.28571428571428650000;
724. x2[28] = -1.77777777777777860000;
725. x2[29] = -1.26984126984127070000;
726. x2[30] = -0.76190476190476275000;
727. x2[31] = -0.25396825396825484000;
728. x2[32] = 0.25396825396825307000;
729. x2[33] = 0.76190476190476275000;
730. x2[34] = 1.26984126984126890000;
731. x2[35] = 1.77777777777777860000;
732. x2[36] = 2.28571428571428470000;
733. x2[37] = 2.79365079365079440000;
734. x2[38] = 3.30158730158730050000;
735. x2[39] = 3.80952380952381020000;
736. x2[40] = 4.31746031746031630000;
737. x2[41] = 4.82539682539682600000;
738. x2[42] = 5.33333333333333210000;
739. x2[43] = 5.84126984126984180000;
740. x2[44] = 6.34920634920634800000;
741. x2[45] = 6.85714285714285770000;
742. x2[46] = 7.36507936507936380000;
743. x2[47] = 7.87301587301587350000;
744. x2[48] = 8.38095238095237960000;
745. x2[49] = 8.88888888888888930000;
746. x2[50] = 9.39682539682539540000;
747. x2[51] = 9.90476190476190510000;
748. x2[52] = 10.41269841269841100000;
749. x2[53] = 10.92063492063492100000;
750. x2[54] = 11.42857142857142700000;
751. x2[55] = 11.93650793650793700000;
752. x2[56] = 12.44444444444444300000;
753. x2[57] = 12.95238095238095300000;
754. x2[58] = 13.46031746031745900000;
755. x2[59] = 13.96825396825396800000;
756. x2[60] = 14.47619047619047400000;
757. x2[61] = 14.98412698412698400000;
758. x2[62] = 15.49206349206349000000;
759. x2[63] = 16.00000000000000000000;
760.
761.
762. var y = new Array();
763. y[0] = +Infinity;
764. y[1] = 1664158979.11096290000000000000;
765. y[2] = 25596.98862206424700000000;
766. y[3] = 51.24224360332205900000;
767. y[4] = 0.80253721621001273000;
768. y[5] = 0.04013281604184240600;
769. y[6] = 0.00427181167466968250;
770. y[7] = 0.00077698684629307839;
771. y[8] = 0.00021140449751288852;
772. y[9] = 0.00007886641216275820;
773. y[10] = 0.00003797970495625904;
774. y[11] = 0.00002260186576944384;
775. y[12] = 0.00001608735704675994;
776. y[13] = 0.00001335526639440840;
777. y[14] = 0.00001267782407825002;
778. y[15] = 0.00001354410739307298;
779. y[16] = 0.00001607404700077214;
780. y[17] = 0.00002096489798949858;
781. y[18] = 0.00002978033411316872;
782. y[19] = 0.00004572015769326707;
783. y[20] = 0.00007536620884896827;
784. y[21] = 0.00013263967558882687;
785. y[22] = 0.00024800091950917796;
786. y[23] = 0.00049049578772052680;
787. y[24] = 0.00102225521238885490;
788. y[25] = 0.00223744147356661880;
789. y[26] = 0.00512739755878587920;
790. y[27] = 0.01226918030754863000;
791. y[28] = 0.03058049475427409400;
792. y[29] = 0.07921771472569966200;
793. y[30] = 0.21285098601167457000;
794. y[31] = 0.59211846233860321000;
795. y[32] = 1.70252376919407730000;
796. y[33] = 5.05197994186350920000;
797. y[34] = 15.44896866758827700000;
798. y[35] = 48.62279949816147700000;
799. y[36] = 157.31086033139039000000;
800. y[37] = 522.60021277476767000000;
801. y[38] = 1780.82316713426990000000;
802. y[39] = 6218.58509846337710000000;
803. y[40] = 22232.54916898025500000000;
804. y[41] = 81310.50695814844200000000;
805. y[42] = 303962.39599994919000000000;
806. y[43] = 1160609.39151835810000000000;
807. y[44] = 4523160.16396183520000000000;
808. y[45] = 17980506.53105686600000000000;
809. y[46] = 72861260.63140085300000000000;
810. y[47] = 300795965.18372804000000000000;
811. y[48] = 1264408843.88636260000000000000;
812. y[49] = 5408983705.82595920000000000000;
813. y[50] = 23536438485.32324600000000000000;
814. y[51] = 104125724201.77888000000000000000;
815. y[52] = 468137079409.17462000000000000000;
816. y[53] = 2137965865913.91260000000000000000;
817. y[54] = 9914368643808.25200000000000000000;
818. y[55] = 46665726995317.89800000000000000000;
819. y[56] = 222863786409039.87000000000000000000;
820. y[57] = 1079534443702065.00000000000000000000;
821. y[58] = 5302037850329952.00000000000000000000;
822. y[59] = 26394813313751084.00000000000000000000;
823. y[60] = 133146543235024720.00000000000000000000;
824. y[61] = 680375082351885950.00000000000000000000;
825. y[62] = 3520878542447823900.00000000000000000000;
826. y[63] = 18446744073709552000.00000000000000000000;
827.
828.
829.
830. var val;
831. for (i = 0; i < vnum; i++)
832. {
833.     val = Math.pow(x1[i], x2[i]);
834.     if (!isEqual(val, y[i]))
835.     {
836.         \$ERROR("\nx1 = " + x1[i] + "\nx2 = " + x2[i] + "\nlibc.pow(x1,x2) = " + y[i] + "\nMath.pow(x1,x2) = " + Math.pow(x1[i], x2[i]) + "\nMath.abs(libc.pow(x1,x2) - Math.pow(x1,x2)) > " + prec + "\n\n");
837.     }
838. }
839.
841. // This code is governed by the BSD license found in the LICENSE file.
842.
843. /**
844.  * Sine is a periodic function with period 2*PI
845.  *
846.  * @path ch15/15.8/15.8.2/15.8.2.16/S15.8.2.16_A6.js
847.  * @description Checking if Math.sin(x) equals to Math.sin(x+n*2*Math.PI) with precision 0.000000000003, where n is an integer from 1 to 100 and x is one of 10 float point values from 0 to 2*Math.PI
848.  */
849.
850. // CHECK#1
851.   prec = 0.000000000003;
852. //prec = 0.000000000000001;
853. period = 2*Math.PI;
854. pernum = 100;
855.
856. a = -pernum * period;
857. b = pernum * period;
858. snum = 9;
859. step = period/snum + 0.0;
860. x = new Array();
861. for (i = 0; i < snum; i++)
862. {
863.     x[i] = a + i*step;
864. }
865. x[9] = a + period;
866.
867. var curval;
868. var curx;
869. var j;
870. for (i = 0; i < snum; i++)
871. {
872.     curval = Math.sin(x[i]);
873.     curx = x[i] + period;
874.     j = 0;
875.     while (curx <= b)
876.     {
877.         curx += period;
878.         j++;
879.         if (Math.abs(Math.sin(curx) - curval) >= prec)
880.         {
881.             \$FAIL("#1: sin is found out to not be periodic:\n Math.abs(Math.sin(" + x[i] + ") - Math.sin(" + x[i] + " + 2*Math.PI*" + j + ")) >= " + prec + "\n Math.sin(" + x[i] + ") === " + curval + "\n Math.sin(" + curx + ") === " + Math.sin(curx));
882.         }
883.     }
884. }
885.
887. // This code is governed by the BSD license found in the LICENSE file.
888.
889. /**
890.  * Math.sin it is recommended that implementations use the approximation algorithms for IEEE 754 arithmetic contained in fdlibm
891.  *
892.  * @path ch15/15.8/15.8.2/15.8.2.16/S15.8.2.16_A7.js
893.  * @description Checking if Math.sin is approximately equals to its mathematical values on the set of 64 argument values; all the sample values is calculated with LibC
894.  */
895.
896. \$INCLUDE("math_precision.js");
897. \$INCLUDE("math_isequal.js");
898.
899. // CHECK#1
900. vnum = 64;
901. var x = new Array();
902. x[0] = 0.00000000000000000000;
903. x[1] = 0.09973310011396169200;
904. x[2] = 0.19946620022792338000;
905. x[3] = 0.29919930034188508000;
906. x[4] = 0.39893240045584677000;
907. x[5] = 0.49866550056980841000;
908. x[6] = 0.59839860068377015000;
909. x[7] = 0.69813170079773179000;
910. x[8] = 0.79786480091169354000;
911. x[9] = 0.89759790102565518000;
912. x[10] = 0.99733100113961681000;
913. x[11] = 1.09706410125357840000;
914. x[12] = 1.19679720136754030000;
915. x[13] = 1.29653030148150190000;
916. x[14] = 1.39626340159546360000;
917. x[15] = 1.49599650170942520000;
918. x[16] = 1.59572960182338710000;
919. x[17] = 1.69546270193734870000;
920. x[18] = 1.79519580205131040000;
921. x[19] = 1.89492890216527200000;
922. x[20] = 1.99466200227923360000;
923. x[21] = 2.09439510239319570000;
924. x[22] = 2.19412820250715690000;
925. x[23] = 2.29386130262111850000;
926. x[24] = 2.39359440273508060000;
927. x[25] = 2.49332750284904230000;
928. x[26] = 2.59306060296300390000;
929. x[27] = 2.69279370307696550000;
930. x[28] = 2.79252680319092720000;
931. x[29] = 2.89225990330488880000;
932. x[30] = 2.99199300341885040000;
933. x[31] = 3.09172610353281210000;
934. x[32] = 3.19145920364677420000;
935. x[33] = 3.29119230376073580000;
936. x[34] = 3.39092540387469740000;
937. x[35] = 3.49065850398865910000;
938. x[36] = 3.59039160410262070000;
939. x[37] = 3.69012470421658230000;
940. x[38] = 3.78985780433054400000;
941. x[39] = 3.88959090444450560000;
942. x[40] = 3.98932400455846730000;
943. x[41] = 4.08905710467242840000;
944. x[42] = 4.18879020478639140000;
945. x[43] = 4.28852330490035260000;
946. x[44] = 4.38825640501431380000;
947. x[45] = 4.48798950512827590000;
948. x[46] = 4.58772260524223710000;
949. x[47] = 4.68745570535619920000;
950. x[48] = 4.78718880547016120000;
951. x[49] = 4.88692190558412240000;
952. x[50] = 4.98665500569808450000;
953. x[51] = 5.08638810581204570000;
954. x[52] = 5.18612120592600780000;
955. x[53] = 5.28585430603996990000;
956. x[54] = 5.38558740615393110000;
957. x[55] = 5.48532050626789310000;
958. x[56] = 5.58505360638185430000;
959. x[57] = 5.68478670649581550000;
960. x[58] = 5.78451980660977760000;
961. x[59] = 5.88425290672373970000;
962. x[60] = 5.98398600683770090000;
963. x[61] = 6.08371910695166300000;
964. x[62] = 6.18345220706562420000;
965. x[63] = 6.28318530717958620000;
966.
967.
968. var y = new Array();
969. y[0] = 0.00000000000000000000;
970. y[1] = 0.09956784659581666100;
971. y[2] = 0.19814614319939758000;
972. y[3] = 0.29475517441090421000;
973. y[4] = 0.38843479627469474000;
974. y[5] = 0.47825397862131819000;
975. y[6] = 0.56332005806362206000;
976. y[7] = 0.64278760968653925000;
977. y[8] = 0.71586684925971844000;
978. y[9] = 0.78183148246802980000;
979. y[10] = 0.84002592315077140000;
980. y[11] = 0.88987180881146855000;
981. y[12] = 0.93087374864420425000;
982. y[13] = 0.96262424695001203000;
983. y[14] = 0.98480775301220802000;
984. y[15] = 0.99720379718118013000;
985. y[16] = 0.99968918200081625000;
986. y[17] = 0.99223920660017206000;
987. y[18] = 0.97492791218182362000;
988. y[19] = 0.94792734616713181000;
989. y[20] = 0.91150585231167325000;
990. y[21] = 0.86602540378443849000;
991. y[22] = 0.81193800571585661000;
992. y[23] = 0.74978120296773443000;
993. y[24] = 0.68017273777091936000;
994. y[25] = 0.60380441032547738000;
995. y[26] = 0.52143520337949811000;
996. y[27] = 0.43388373911755823000;
997. y[28] = 0.34202014332566888000;
998. y[29] = 0.24675739769029384000;
999. y[30] = 0.14904226617617472000;
1000. y[31] = 0.04984588566069748200;
1001. y[32] = -0.04984588566069723300;
1002. y[33] = -0.14904226617617447000;
1003. y[34] = -0.24675739769029362000;
1004. y[35] = -0.34202014332566866000;
1005. y[36] = -0.43388373911755801000;
1006. y[37] = -0.52143520337949789000;
1007. y[38] = -0.60380441032547716000;
1008. y[39] = -0.68017273777091913000;
1009. y[40] = -0.74978120296773398000;
1010. y[41] = -0.81193800571585595000;
1011. y[42] = -0.86602540378443882000;
1012. y[43] = -0.91150585231167314000;
1013. y[44] = -0.94792734616713159000;
1014. y[45] = -0.97492791218182362000;
1015. y[46] = -0.99223920660017195000;
1016. y[47] = -0.99968918200081625000;
1017. y[48] = -0.99720379718118013000;
1018. y[49] = -0.98480775301220813000;
1019. y[50] = -0.96262424695001203000;
1020. y[51] = -0.93087374864420447000;
1021. y[52] = -0.88987180881146866000;
1022. y[53] = -0.84002592315077129000;
1023. y[54] = -0.78183148246802991000;
1024. y[55] = -0.71586684925971833000;
1025. y[56] = -0.64278760968653958000;
1026. y[57] = -0.56332005806362273000;
1027. y[58] = -0.47825397862131858000;
1028. y[59] = -0.38843479627469474000;
1029. y[60] = -0.29475517441090471000;
1030. y[61] = -0.19814614319939772000;
1031. y[62] = -0.09956784659581728600;
1032. y[63] = -0.0000000000000002449293598294706400;
1033.
1034.
1035. var val;
1036. for (i = 0; i < vnum; i++)
1037. {
1038.     val = Math.sin(x[i]);
1039.     if (!isEqual(val, y[i]))
1040.     {
1041.         \$ERROR("\nx = " + x[i] + "\nlibc.sin(x) = " + y[i] + "\nMath.sin(x) = " + Math.sin(x[i]) + "\nMath.abs(libc.sin(x) - Math.sin(x)) > " + prec + "\n\n");
1042.     }
1043. }
1044.
1046. // This code is governed by the BSD license found in the LICENSE file.
1047.
1048. /**
1049.  * Math.sqrt, recommended that implementations use the approximation algorithms for IEEE 754 arithmetic contained in fdlibm
1050.  *
1051.  * @path ch15/15.8/15.8.2/15.8.2.17/S15.8.2.17_A6.js
1052.  * @description Checking if Math.sqrt is approximately equals to its mathematical values on the set of 64 argument values; all the sample values is calculated with LibC
1053.  */
1054.
1055. \$INCLUDE("math_precision.js");
1056. \$INCLUDE("math_isequal.js");
1057.
1058. // CHECK#1
1059. vnum = 64;
1060. var x = new Array();
1061. x[0] = 0.00000000000000000000;
1062. x[1] = 0.25396825396825395000;
1063. x[2] = 0.50793650793650791000;
1064. x[3] = 0.76190476190476186000;
1065. x[4] = 1.01587301587301580000;
1066. x[5] = 1.26984126984126980000;
1067. x[6] = 1.52380952380952370000;
1068. x[7] = 1.77777777777777770000;
1069. x[8] = 2.03174603174603160000;
1070. x[9] = 2.28571428571428560000;
1071. x[10] = 2.53968253968253950000;
1072. x[11] = 2.79365079365079350000;
1073. x[12] = 3.04761904761904740000;
1074. x[13] = 3.30158730158730140000;
1075. x[14] = 3.55555555555555540000;
1076. x[15] = 3.80952380952380930000;
1077. x[16] = 4.06349206349206330000;
1078. x[17] = 4.31746031746031720000;
1079. x[18] = 4.57142857142857120000;
1080. x[19] = 4.82539682539682510000;
1081. x[20] = 5.07936507936507910000;
1082. x[21] = 5.33333333333333300000;
1083. x[22] = 5.58730158730158700000;
1084. x[23] = 5.84126984126984090000;
1085. x[24] = 6.09523809523809490000;
1086. x[25] = 6.34920634920634890000;
1087. x[26] = 6.60317460317460280000;
1088. x[27] = 6.85714285714285680000;
1089. x[28] = 7.11111111111111070000;
1090. x[29] = 7.36507936507936470000;
1091. x[30] = 7.61904761904761860000;
1092. x[31] = 7.87301587301587260000;
1093. x[32] = 8.12698412698412650000;
1094. x[33] = 8.38095238095238140000;
1095. x[34] = 8.63492063492063440000;
1096. x[35] = 8.88888888888888930000;
1097. x[36] = 9.14285714285714230000;
1098. x[37] = 9.39682539682539720000;
1099. x[38] = 9.65079365079365030000;
1100. x[39] = 9.90476190476190510000;
1101. x[40] = 10.15873015873015800000;
1102. x[41] = 10.41269841269841300000;
1103. x[42] = 10.66666666666666600000;
1104. x[43] = 10.92063492063492100000;
1105. x[44] = 11.17460317460317400000;
1106. x[45] = 11.42857142857142900000;
1107. x[46] = 11.68253968253968200000;
1108. x[47] = 11.93650793650793700000;
1109. x[48] = 12.19047619047619000000;
1110. x[49] = 12.44444444444444500000;
1111. x[50] = 12.69841269841269800000;
1112. x[51] = 12.95238095238095300000;
1113. x[52] = 13.20634920634920600000;
1114. x[53] = 13.46031746031746000000;
1115. x[54] = 13.71428571428571400000;
1116. x[55] = 13.96825396825396800000;
1117. x[56] = 14.22222222222222100000;
1118. x[57] = 14.47619047619047600000;
1119. x[58] = 14.73015873015872900000;
1120. x[59] = 14.98412698412698400000;
1121. x[60] = 15.23809523809523700000;
1122. x[61] = 15.49206349206349200000;
1123. x[62] = 15.74603174603174500000;
1124. x[63] = 16.00000000000000000000;
1125.
1126.
1127.
1128. var y = new Array();
1129. y[0] = 0.00000000000000000000;
1130. y[1] = 0.50395263067896967000;
1131. y[2] = 0.71269664509979835000;
1132. y[3] = 0.87287156094396945000;
1133. y[4] = 1.00790526135793930000;
1134. y[5] = 1.12687233963802200000;
1135. y[6] = 1.23442679969673530000;
1136. y[7] = 1.33333333333333330000;
1137. y[8] = 1.42539329019959670000;
1138. y[9] = 1.51185789203690880000;
1139. y[10] = 1.59363814577919150000;
1140. y[11] = 1.67142178807468980000;
1141. y[12] = 1.74574312188793890000;
1142. y[13] = 1.81702705031799170000;
1143. y[14] = 1.88561808316412670000;
1144. y[15] = 1.95180014589706640000;
1145. y[16] = 2.01581052271587870000;
1146. y[17] = 2.07784992659727900000;
1147. y[18] = 2.13808993529939520000;
1148. y[19] = 2.19667858946110380000;
1149. y[20] = 2.25374467927604400000;
1150. y[21] = 2.30940107675850290000;
1151. y[22] = 2.36374736114111530000;
1152. y[23] = 2.41687191246657520000;
1153. y[24] = 2.46885359939347060000;
1154. y[25] = 2.51976315339484810000;
1155. y[26] = 2.56966429775848400000;
1156. y[27] = 2.61861468283190830000;
1157. y[28] = 2.66666666666666650000;
1158. y[29] = 2.71386797119523940000;
1159. y[30] = 2.76026223736941700000;
1160. y[31] = 2.80588949764880670000;
1161. y[32] = 2.85078658039919340000;
1162. y[33] = 2.89498745782298350000;
1163. y[34] = 2.93852354676981160000;
1164. y[35] = 2.98142396999971960000;
1165. y[36] = 3.02371578407381760000;
1166. y[37] = 3.06542417893925380000;
1167. y[38] = 3.10657265339049320000;
1168. y[39] = 3.14718316987777280000;
1169. y[40] = 3.18727629155838300000;
1170. y[41] = 3.22687130401855570000;
1171. y[42] = 3.26598632371090410000;
1172. y[43] = 3.30463839483761390000;
1173. y[44] = 3.34284357614937950000;
1174. y[45] = 3.38061701891406630000;
1175. y[46] = 3.41797303712883060000;
1176. y[47] = 3.45492517089848670000;
1177. y[48] = 3.49148624377587780000;
1178. y[49] = 3.52766841475278750000;
1179. y[50] = 3.56348322549899170000;
1180. y[51] = 3.59894164336974940000;
1181. y[52] = 3.63405410063598340000;
1182. y[53] = 3.66883053033489940000;
1183. y[54] = 3.70328039909020570000;
1184. y[55] = 3.73741273720925400000;
1185. y[56] = 3.77123616632825340000;
1186. y[57] = 3.80475892484536750000;
1187. y[58] = 3.83798889135426350000;
1188. y[59] = 3.87093360626696680000;
1189. y[60] = 3.90360029179413280000;
1190. y[61] = 3.93599587043272870000;
1191. y[62] = 3.96812698209517300000;
1192. y[63] = 4.00000000000000000000;
1193.
1194.
1195. var val;
1196. for (i = 0; i < vnum; i++)
1197. {
1198.     val = Math.sqrt(x[i]);
1199.     if (!isEqual(val, y[i]))
1200.     {
1201.         \$ERROR("\nx = " + x[i] + "\nlibc.sqrt(x) = " + y[i] + "\nMath.sqrt(x) = " + Math.sqrt(x[i]) + "\nMath.abs(libc.sqrt(x) - Math.sqrt(x)) > " + prec + "\n\n");
1202.     }
1203. }
1204.
1206. // This code is governed by the BSD license found in the LICENSE file.
1207.
1208. /**
1209.  * Tangent is a periodic function with period PI
1210.  *
1211.  * @path ch15/15.8/15.8.2/15.8.2.18/S15.8.2.18_A6.js
1212.  * @description Checking if Math.tan(x) equals to Math.tan(x+n*Math.PI) with precision 0.000000000003, where n is an integer from 1 to 100 and x is one of 10 float point values from 0 to Math.PI
1213.  */
1214.
1215. // CHECK#1
1216.   prec = 0.00000000003;
1217. //prec = 0.000000000000001;
1218. period = Math.PI;
1219. pernum = 100;
1220.
1221. a = -pernum * period + period/2;
1222. b = pernum * period - period/2;
1223. snum = 9;
1224. step = period/(snum + 2);
1225. x = new Array();
1226. for (i = 0; i <= snum; i++)    //// We exlude special points
1227. {                              ////           in this cycle.
1228.     x[i] = a + (i+1)*step;     ////
1229. }                              ////
1230.
1231.
1232. var curval;
1233. var curx;
1234. var j;
1235. for (i = 0; i < snum; i++)
1236. {
1237.     curval = Math.tan(x[i]);
1238.     curx = x[i] + period;
1239.     j = 0;
1240.     while (curx <= b)
1241.     {
1242.         curx += period;
1243.         j++;
1244.         if (Math.abs(Math.tan(curx) - curval) >= prec)
1245.         {
1246.             \$FAIL("#1: tan is found out to not be periodic:\n Math.abs(Math.tan(" + x[i] + ") - Math.tan(" + x[i] + " + 2*Math.PI*" + j + ")) >= " + prec + "\n Math.tan(" + x[i] + ") === " + curval + "\n Math.tan(" + curx + ") === " + Math.tan(curx));
1247.         }
1248.     }
1249. }
1250.
1252. // This code is governed by the BSD license found in the LICENSE file.
1253.
1254. /**
1255.  * If x is +Infinity, Math.atan(x) is an implementation-dependent approximation to +PI/2
1256.  *
1257.  * @path ch15/15.8/15.8.2/15.8.2.4/S15.8.2.4_A4.js
1258.  * @description Checking if Math.atan(+Infinity) is an approximation to +PI/2
1259.  */
1260.
1261. \$INCLUDE("math_precision.js");
1262. \$INCLUDE("math_isequal.js");
1263.
1264. // CHECK#1
1265.
1266. var x = +Infinity;
1267. if (!isEqual(Math.atan(x),Math.PI/2))
1268. {
1269.     \$ERROR("#1: '!isEqual(Math.atan(+Infinity), Math.PI/2)'");
1270. }
1271.
1273. // This code is governed by the BSD license found in the LICENSE file.
1274.
1275. /**
1276.  * If x is -Infinity, Math.atan(x) is an implementation-dependent approximation to -PI/2
1277.  *
1278.  * @path ch15/15.8/15.8.2/15.8.2.4/S15.8.2.4_A5.js
1279.  * @description Checking if Math.atan(-Infinity) is an approximation to -PI/2
1280.  */
1281.
1282. \$INCLUDE("math_precision.js");
1283. \$INCLUDE("math_isequal.js");
1284.
1285. // CHECK#1
1286.
1287. var x = -Infinity;
1288. if (!isEqual(Math.atan(x), -Math.PI/2))
1289. {
1290.     \$ERROR("#1: '!isEqual(Math.atan(-Infinity), -Math.PI/2)'");
1291. }
1292.
1294. // This code is governed by the BSD license found in the LICENSE file.
1295.
1296. /**
1297.  * If y is -0 and x is -0, Math.atan2(y,x) is an implementation-dependent approximation to -PI
1298.  *
1299.  * @path ch15/15.8/15.8.2/15.8.2.5/S15.8.2.5_A10.js
1300.  * @description Checking if Math.atan2(-0,-0) is an approximation to -PI
1301.  */
1302.
1303. \$INCLUDE("math_precision.js");
1304. \$INCLUDE("math_isequal.js");
1305.
1306. // CHECK#1
1307. //prec = 0.00000000000001;
1308. y = -0;
1309. x = -0;
1310. if (!isEqual(Math.atan2(y,x), -Math.PI))
1311.     \$ERROR("#1: !isEqual(Math.atan2(-0,-0), -Math.PI)");
1312.
1314. // This code is governed by the BSD license found in the LICENSE file.
1315.
1316. /**
1317.  * If y is equal to -0 and x<0, Math.atan2(y,x) is an implementation-dependent approximation to -PI
1318.  *
1319.  * @path ch15/15.8/15.8.2/15.8.2.5/S15.8.2.5_A11.js
1320.  * @description Checking if Math.atan2(-0,x) is an approximation to -PI, where x<0
1321.  */
1322.
1323. \$INCLUDE("math_precision.js");
1324. \$INCLUDE("math_isequal.js");
1325.
1326. // CHECK#1
1327. y = -0;
1328. //prec = 0.00000000000001;
1329. x = new Array();
1330. x[0] = -0.000000000000001;
1331. x[2] = -Infinity;
1332. x[1] = -1;
1333. xnum = 3;
1334.
1335. for (i = 0; i < xnum; i++)
1336. {
1337.     if (!isEqual(Math.atan2(y,x[i]), - Math.PI))
1338.         \$FAIL("#1: Math.abs(Math.atan2(" + y + ", " + x[i] + ") + Math.PI) >= " + prec);
1339. }
1340.
1342. // This code is governed by the BSD license found in the LICENSE file.
1343.
1344. /**
1345.  * If y<0 and x is +0, Math.atan2(y,x) is an implementation-dependent approximation to -PI/2
1346.  *
1347.  * @path ch15/15.8/15.8.2/15.8.2.5/S15.8.2.5_A12.js
1348.  * @description Checking if Math.atan2(y,+0) is an approximation to -PI/2, where y<0
1349.  */
1350.
1351. \$INCLUDE("math_precision.js");
1352. \$INCLUDE("math_isequal.js");
1353.
1354. // CHECK#1
1355. x = +0;
1356. //prec = 0.00000000000001;
1357. y = new Array();
1358. y[0] = -0.000000000000001;
1359. y[2] = -Infinity;
1360. y[1] = -1;
1361. ynum = 3;
1362.
1363. for (i = 0; i < ynum; i++)
1364. {
1365.     if (!isEqual(Math.atan2(y[i],x), -(Math.PI)/2))
1366.         \$FAIL("#1: Math.abs(Math.atan2(" + y[i] + ", " + x + ") + ((Math.PI)/2)) >= " + prec);
1367. }
1368.
1370. // This code is governed by the BSD license found in the LICENSE file.
1371.
1372. /**
1373.  * If y<0 and x is -0, Math.atan2(y,x) is an implementation-dependent approximation to -PI/2
1374.  *
1375.  * @path ch15/15.8/15.8.2/15.8.2.5/S15.8.2.5_A13.js
1376.  * @description Checking if Math.atan2(y,-0) is an approximation to -PI/2, where y<0
1377.  */
1378.
1379. \$INCLUDE("math_precision.js");
1380. \$INCLUDE("math_isequal.js");
1381.
1382. // CHECK#1
1383. x = -0;
1384. //prec = 0.00000000000001;
1385. y = new Array();
1386. y[0] = -0.000000000000001;
1387. y[2] = -Infinity;
1388. y[1] = -1;
1389. ynum = 3;
1390.
1391. for (i = 0; i < ynum; i++)
1392. {
1393.     if (!isEqual(Math.atan2(y[i],x), -(Math.PI)/2))
1394.         \$FAIL("#1: Math.abs(Math.atan2(" + y[i] + ", -0) + ((Math.PI)/2)) >= " + prec);
1395. }
1396.
1398. // This code is governed by the BSD license found in the LICENSE file.
1399.
1400. /**
1401.  * If y>0 and y is finite and x is equal to -Infinity, Math.atan2(y,x) is an implementation-dependent approximation to +PI
1402.  *
1403.  * @path ch15/15.8/15.8.2/15.8.2.5/S15.8.2.5_A15.js
1404.  * @description Checking if Math.atan2(y,x) is an approximation to +PI, where y>0 and y is finite and x is equal to -Infinity
1405.  */
1406.
1407. \$INCLUDE("math_precision.js");
1408. \$INCLUDE("math_isequal.js");
1409.
1410. // CHECK#1
1411. x = -Infinity;
1412. y = new Array();
1413. y[0] = 0.000000000000001;
1414. y[1] = 1;
1415. y[2] = 1.7976931348623157E308; //largest finite number
1416. ynum = 3;
1417.
1418. for (i = 0; i < ynum; i++)
1419. {
1420.     if (!isEqual(Math.atan2(y[i],x),Math.PI))
1421.         \$FAIL("#1: Math.abs(Math.atan2(" + y[i] + ", " + x + ") - Math.PI) >= " + prec);
1422. }
1423.
1425. // This code is governed by the BSD license found in the LICENSE file.
1426.
1427. /**
1428.  * If y<0 and y is finite and x is equal to -Infinity, Math.atan2(y,x) is an implementation-dependent approximation to -PI
1429.  *
1430.  * @path ch15/15.8/15.8.2/15.8.2.5/S15.8.2.5_A17.js
1431.  * @description Checking if Math.atan2(y,x) is an approximation to -PI, where y<0 and y is finite and x is equal to -Infinity
1432.  */
1433.
1434. \$INCLUDE("math_precision.js");
1435. \$INCLUDE("math_isequal.js");
1436.
1437. // CHECK#1
1438. x = -Infinity;
1439. y = new Array();
1440. y[0] = -0.000000000000001;
1441. y[1] = -1;
1442. y[2] = -1.7976931348623157E308; //largest (by module) finite number
1443. ynum = 3;
1444.
1445. for (i = 0; i < ynum; i++)
1446. {
1447.     if (!isEqual(Math.atan2(y[i],x), -Math.PI))
1448.         \$FAIL("#1: Math.abs(Math.atan2(" + y[i] + ", " + x + ") + Math.PI) >= " + prec);
1449. }
1450.
1452. // This code is governed by the BSD license found in the LICENSE file.
1453.
1454. /**
1455.  * If y is +Infinity and x is finite, Math.atan2(y,x) is an implementation-dependent approximation to +PI/2
1456.  *
1457.  * @path ch15/15.8/15.8.2/15.8.2.5/S15.8.2.5_A18.js
1458.  * @description Checking if Math.atan2(y,x) is an approximation to +PI/2, where y is +Infinity and x is finite
1459.  */
1460.
1461. \$INCLUDE("math_precision.js");
1462. \$INCLUDE("math_isequal.js");
1463.
1464. // CHECK#1
1465. y = +Infinity;
1466. x = new Array();
1467. x[0] = 0.000000000000001;
1468. x[1] = 1;
1469. x[2] = 1.7976931348623157E308; //largest finite number
1470. x[3] = -0.000000000000001;
1471. x[4] = -1;
1472. x[5] = -1.7976931348623157E308; //largest (by module) finite number
1473.
1474. xnum = 6;
1475.
1476. for (i = 0; i < xnum; i++)
1477. {
1478.     if (!isEqual(Math.atan2(y,x[i]), (Math.PI)/2))
1479.         \$FAIL("#1: Math.abs(Math.atan2(" + y + ", " + x[i] + ") - (Math.PI/2)) >= " + prec);
1480. }
1481.
1483. // This code is governed by the BSD license found in the LICENSE file.
1484.
1485. /**
1486.  * If y is -Infinity and x is finite, Math.atan2(y,x) is an implementation-dependent approximation to -PI/2
1487.  *
1488.  * @path ch15/15.8/15.8.2/15.8.2.5/S15.8.2.5_A19.js
1489.  * @description Checking if Math.atan2(y,x) is an approximation to -PI/2, where y is -Infinity and x is finite
1490.  */
1491.
1492. \$INCLUDE("math_precision.js");
1493. \$INCLUDE("math_isequal.js");
1494.
1495. // CHECK#1
1496. //prec = 0.00000000000001;
1497. y = -Infinity;
1498. x = new Array();
1499. x[0] = 0.000000000000001;
1500. x[1] = 1;
1501. x[2] = 1.7976931348623157E308; //largest finite number
1502. x[3] = -0.000000000000001;
1503. x[4] = -1;
1504. x[5] = -1.7976931348623157E308; //largest (by module) finite number
1505.
1506. xnum = 6;
1507.
1508. for (i = 0; i < xnum; i++)
1509. {
1510.     if (!isEqual(Math.atan2(y,x[i]), -(Math.PI)/2))
1511.         \$FAIL("#1: Math.abs(Math.atan2(" + y + ", " + x[i] + ") + (Math.PI/2)) >= " + prec);
1512. }
1513.
1515. // This code is governed by the BSD license found in the LICENSE file.
1516.
1517. /**
1518.  * If y>0 and x is +0, Math.atan2(y,x) is an implementation-dependent approximation to +PI/2
1519.  *
1520.  * @path ch15/15.8/15.8.2/15.8.2.5/S15.8.2.5_A2.js
1521.  * @description Checking if Math.atan2(y,x) is an approximation to +PI/2, where y>0 and x is +0
1522.  */
1523.
1524. \$INCLUDE("math_precision.js");
1525. \$INCLUDE("math_isequal.js");
1526.
1527. // CHECK#1
1528. x = +0;
1529. //prec = 0.00000000000001;
1530. y = new Array();
1531. y[0] = 0.000000000000001;
1532. y[2] = +Infinity;
1533. y[1] = 1;
1534. ynum = 3;
1535.
1536. for (i = 0; i < ynum; i++)
1537. {
1538.     if (!isEqual(Math.atan2(y[i],x),(Math.PI)/2))
1539.         \$FAIL("#1: Math.abs(Math.atan2(" + y[i] + ", " + x + ") - ((Math.PI)/2)) >= " + prec);
1540. }
1541.
1543. // This code is governed by the BSD license found in the LICENSE file.
1544.
1545. /**
1546.  * If y is equal to +Infinity and x is equal to -Infinity, Math.atan2(y,x) is an implementation-dependent approximation to +3*PI/4
1547.  *
1548.  * @path ch15/15.8/15.8.2/15.8.2.5/S15.8.2.5_A21.js
1549.  * @description Checking if Math.atan2(y,x) is an approximation to +3*PI/4, where y is equal to +Infinity and x is equal to -Infinity
1550.  */
1551.
1552. \$INCLUDE("math_precision.js");
1553. \$INCLUDE("math_isequal.js");
1554.
1555. // CHECK#1
1556. //prec = 0.00000000000001;
1557. y = +Infinity;
1558. x = -Infinity;
1559.
1560. if (!isEqual(Math.atan2(y,x), (3*Math.PI)/4))
1561.     \$ERROR("#1: Math.abs(Math.atan2(" + y + ", " + x + ") - (3*Math.PI/4)) >= " + prec);
1562.
1564. // This code is governed by the BSD license found in the LICENSE file.
1565.
1566. /**
1567.  * If y is equal to -Infinity and x is equal to -Infinity, Math.atan2(y,x) is an implementation-dependent approximation to -3*PI/4
1568.  *
1569.  * @path ch15/15.8/15.8.2/15.8.2.5/S15.8.2.5_A23.js
1570.  * @description Checking if Math.atan2(y,x) is an approximation to -3*PI/4, where y is equal to -Infinity and x is equal to -Infinity
1571.  */
1572.
1573. \$INCLUDE("math_precision.js");
1574. \$INCLUDE("math_isequal.js");
1575.
1576. // CHECK#1
1577. //prec = 0.00000000000001;
1578. y = -Infinity;
1579. x = -Infinity;
1580.
1581. if (!isEqual(Math.atan2(y,x), -(3*Math.PI)/4))
1582.     \$ERROR("#1: Math.abs(Math.atan2(" + y + ", " + x + ") + (3*Math.PI/4)) >= " + prec);
1583.
1585. // This code is governed by the BSD license found in the LICENSE file.
1586.
1587. /**
1588.  * Math.atan2, recommended that implementations use the approximation algorithms for IEEE 754 arithmetic contained in fdlibm
1589.  *
1590.  * @path ch15/15.8/15.8.2/15.8.2.5/S15.8.2.5_A24.js
1591.  * @description Checking if Math.atan2(argument1, argument2) is approximately equals to its mathematical values on the set of 64 argument1 values and 64 argument2 values; all the sample values is calculated with LibC
1592.  */
1593.
1594. \$INCLUDE("math_precision.js");
1595. \$INCLUDE("math_isequal.js");
1596.
1597. // CHECK#1
1598. vnum = 64;
1599. var x1 = new Array();
1600. x1[0] = -16.00000000000000000000;
1601. x1[1] = -15.49206349206349200000;
1602. x1[2] = -14.98412698412698400000;
1603. x1[3] = -14.47619047619047600000;
1604. x1[4] = -13.96825396825396800000;
1605. x1[5] = -13.46031746031746000000;
1606. x1[6] = -12.95238095238095300000;
1607. x1[7] = -12.44444444444444500000;
1608. x1[8] = -11.93650793650793700000;
1609. x1[9] = -11.42857142857142900000;
1610. x1[10] = -10.92063492063492100000;
1611. x1[11] = -10.41269841269841300000;
1612. x1[12] = -9.90476190476190510000;
1613. x1[13] = -9.39682539682539720000;
1614. x1[14] = -8.88888888888888930000;
1615. x1[15] = -8.38095238095238140000;
1616. x1[16] = -7.87301587301587350000;
1617. x1[17] = -7.36507936507936560000;
1618. x1[18] = -6.85714285714285770000;
1619. x1[19] = -6.34920634920634970000;
1620. x1[20] = -5.84126984126984180000;
1621. x1[21] = -5.33333333333333390000;
1622. x1[22] = -4.82539682539682600000;
1623. x1[23] = -4.31746031746031810000;
1624. x1[24] = -3.80952380952381020000;
1625. x1[25] = -3.30158730158730230000;
1626. x1[26] = -2.79365079365079440000;
1627. x1[27] = -2.28571428571428650000;
1628. x1[28] = -1.77777777777777860000;
1629. x1[29] = -1.26984126984127070000;
1630. x1[30] = -0.76190476190476275000;
1631. x1[31] = -0.25396825396825484000;
1632. x1[32] = 0.25396825396825307000;
1633. x1[33] = 0.76190476190476275000;
1634. x1[34] = 1.26984126984126890000;
1635. x1[35] = 1.77777777777777860000;
1636. x1[36] = 2.28571428571428470000;
1637. x1[37] = 2.79365079365079440000;
1638. x1[38] = 3.30158730158730050000;
1639. x1[39] = 3.80952380952381020000;
1640. x1[40] = 4.31746031746031630000;
1641. x1[41] = 4.82539682539682600000;
1642. x1[42] = 5.33333333333333210000;
1643. x1[43] = 5.84126984126984180000;
1644. x1[44] = 6.34920634920634800000;
1645. x1[45] = 6.85714285714285770000;
1646. x1[46] = 7.36507936507936380000;
1647. x1[47] = 7.87301587301587350000;
1648. x1[48] = 8.38095238095237960000;
1649. x1[49] = 8.88888888888888930000;
1650. x1[50] = 9.39682539682539540000;
1651. x1[51] = 9.90476190476190510000;
1652. x1[52] = 10.41269841269841100000;
1653. x1[53] = 10.92063492063492100000;
1654. x1[54] = 11.42857142857142700000;
1655. x1[55] = 11.93650793650793700000;
1656. x1[56] = 12.44444444444444300000;
1657. x1[57] = 12.95238095238095300000;
1658. x1[58] = 13.46031746031745900000;
1659. x1[59] = 13.96825396825396800000;
1660. x1[60] = 14.47619047619047400000;
1661. x1[61] = 14.98412698412698400000;
1662. x1[62] = 15.49206349206349000000;
1663. x1[63] = 16.00000000000000000000;
1664.
1665.
1666. var x2 = new Array();
1667. x2[0] = -8.00000000000000000000;
1668. x2[1] = -7.74603174603174600000;
1669. x2[2] = -7.49206349206349210000;
1670. x2[3] = -7.23809523809523810000;
1671. x2[4] = -6.98412698412698420000;
1672. x2[5] = -6.73015873015873020000;
1673. x2[6] = -6.47619047619047630000;
1674. x2[7] = -6.22222222222222230000;
1675. x2[8] = -5.96825396825396840000;
1676. x2[9] = -5.71428571428571440000;
1677. x2[10] = -5.46031746031746050000;
1678. x2[11] = -5.20634920634920650000;
1679. x2[12] = -4.95238095238095260000;
1680. x2[13] = -4.69841269841269860000;
1681. x2[14] = -4.44444444444444460000;
1682. x2[15] = -4.19047619047619070000;
1683. x2[16] = -3.93650793650793670000;
1684. x2[17] = -3.68253968253968280000;
1685. x2[18] = -3.42857142857142880000;
1686. x2[19] = -3.17460317460317490000;
1687. x2[20] = -2.92063492063492090000;
1688. x2[21] = -2.66666666666666700000;
1689. x2[22] = -2.41269841269841300000;
1690. x2[23] = -2.15873015873015910000;
1691. x2[24] = -1.90476190476190510000;
1692. x2[25] = -1.65079365079365110000;
1693. x2[26] = -1.39682539682539720000;
1694. x2[27] = -1.14285714285714320000;
1695. x2[28] = -0.88888888888888928000;
1696. x2[29] = -0.63492063492063533000;
1697. x2[30] = -0.38095238095238138000;
1698. x2[31] = -0.12698412698412742000;
1699. x2[32] = 0.12698412698412653000;
1700. x2[33] = 0.38095238095238138000;
1701. x2[34] = 0.63492063492063444000;
1702. x2[35] = 0.88888888888888928000;
1703. x2[36] = 1.14285714285714230000;
1704. x2[37] = 1.39682539682539720000;
1705. x2[38] = 1.65079365079365030000;
1706. x2[39] = 1.90476190476190510000;
1707. x2[40] = 2.15873015873015820000;
1708. x2[41] = 2.41269841269841300000;
1709. x2[42] = 2.66666666666666610000;
1710. x2[43] = 2.92063492063492090000;
1711. x2[44] = 3.17460317460317400000;
1712. x2[45] = 3.42857142857142880000;
1713. x2[46] = 3.68253968253968190000;
1714. x2[47] = 3.93650793650793670000;
1715. x2[48] = 4.19047619047618980000;
1716. x2[49] = 4.44444444444444460000;
1717. x2[50] = 4.69841269841269770000;
1718. x2[51] = 4.95238095238095260000;
1719. x2[52] = 5.20634920634920560000;
1720. x2[53] = 5.46031746031746050000;
1721. x2[54] = 5.71428571428571350000;
1722. x2[55] = 5.96825396825396840000;
1723. x2[56] = 6.22222222222222140000;
1724. x2[57] = 6.47619047619047630000;
1725. x2[58] = 6.73015873015872930000;
1726. x2[59] = 6.98412698412698420000;
1727. x2[60] = 7.23809523809523720000;
1728. x2[61] = 7.49206349206349210000;
1729. x2[62] = 7.74603174603174520000;
1730. x2[63] = 8.00000000000000000000;
1731.
1732.
1733. var y = new Array();
1734. y[0] = -2.03444393579570270000;
1735. y[1] = -2.03444393579570270000;
1736. y[2] = -2.03444393579570270000;
1737. y[3] = -2.03444393579570270000;
1738. y[4] = -2.03444393579570270000;
1739. y[5] = -2.03444393579570270000;
1740. y[6] = -2.03444393579570270000;
1741. y[7] = -2.03444393579570270000;
1742. y[8] = -2.03444393579570270000;
1743. y[9] = -2.03444393579570270000;
1744. y[10] = -2.03444393579570270000;
1745. y[11] = -2.03444393579570270000;
1746. y[12] = -2.03444393579570270000;
1747. y[13] = -2.03444393579570270000;
1748. y[14] = -2.03444393579570270000;
1749. y[15] = -2.03444393579570270000;
1750. y[16] = -2.03444393579570270000;
1751. y[17] = -2.03444393579570270000;
1752. y[18] = -2.03444393579570270000;
1753. y[19] = -2.03444393579570270000;
1754. y[20] = -2.03444393579570270000;
1755. y[21] = -2.03444393579570270000;
1756. y[22] = -2.03444393579570270000;
1757. y[23] = -2.03444393579570270000;
1758. y[24] = -2.03444393579570270000;
1759. y[25] = -2.03444393579570270000;
1760. y[26] = -2.03444393579570270000;
1761. y[27] = -2.03444393579570270000;
1762. y[28] = -2.03444393579570270000;
1763. y[29] = -2.03444393579570270000;
1764. y[30] = -2.03444393579570270000;
1765. y[31] = -2.03444393579570270000;
1766. y[32] = 1.10714871779409040000;
1767. y[33] = 1.10714871779409040000;
1768. y[34] = 1.10714871779409040000;
1769. y[35] = 1.10714871779409040000;
1770. y[36] = 1.10714871779409040000;
1771. y[37] = 1.10714871779409040000;
1772. y[38] = 1.10714871779409040000;
1773. y[39] = 1.10714871779409040000;
1774. y[40] = 1.10714871779409040000;
1775. y[41] = 1.10714871779409040000;
1776. y[42] = 1.10714871779409040000;
1777. y[43] = 1.10714871779409040000;
1778. y[44] = 1.10714871779409040000;
1779. y[45] = 1.10714871779409040000;
1780. y[46] = 1.10714871779409040000;
1781. y[47] = 1.10714871779409040000;
1782. y[48] = 1.10714871779409040000;
1783. y[49] = 1.10714871779409040000;
1784. y[50] = 1.10714871779409040000;
1785. y[51] = 1.10714871779409040000;
1786. y[52] = 1.10714871779409040000;
1787. y[53] = 1.10714871779409040000;
1788. y[54] = 1.10714871779409040000;
1789. y[55] = 1.10714871779409040000;
1790. y[56] = 1.10714871779409040000;
1791. y[57] = 1.10714871779409040000;
1792. y[58] = 1.10714871779409040000;
1793. y[59] = 1.10714871779409040000;
1794. y[60] = 1.10714871779409040000;
1795. y[61] = 1.10714871779409040000;
1796. y[62] = 1.10714871779409040000;
1797. y[63] = 1.10714871779409040000;
1798.
1799.
1800.
1801. var val;
1802. for (i = 0; i < vnum; i++)
1803. {
1804.     val = Math.atan2(x1[i], x2[i]);
1805.     if (!isEqual(val, y[i]))
1806.     {
1807.         \$ERROR("\nx1 = " + x1[i] + "\nx2 = " + x2[i] + "\nlibc.atan2(x1,x2) = " + y[i] + "\nMath.atan2(x1,x2) = " + Math.atan2(x1[i],x2[i]) + "\nMath.abs(libc.atan2(x1,x2) - Math.atan2(x1,x2)) > " + prec + "\n\n");
1808.     }
1809. }
1810.
1812. // This code is governed by the BSD license found in the LICENSE file.
1813.
1814. /**
1815.  * If y>0 and x is -0, Math.atan2(y,x) is an implementation-dependent approximation to +PI/2
1816.  *
1817.  * @path ch15/15.8/15.8.2/15.8.2.5/S15.8.2.5_A3.js
1818.  * @description Checking if Math.atan2(y,x) is an approximation to +PI/2, where y>0 and x is -0
1819.  */
1820.
1821. \$INCLUDE("math_precision.js");
1822. \$INCLUDE("math_isequal.js");
1823.
1824. // CHECK#1
1825. x = -0;
1826. //prec = 0.00000000000001;
1827. y = new Array();
1828. y[0] = 0.000000000000001;
1829. y[2] = +Infinity;
1830. y[1] = 1;
1831. ynum = 3;
1832.
1833. for (i = 0; i < ynum; i++)
1834. {
1835.     if (!isEqual(Math.atan2(y[i],x), (Math.PI)/2))
1836.         \$FAIL("#1: Math.abs(Math.atan2(" + y[i] + ", " + x + ") - ((Math.PI)/2)) >= " + prec);
1837. }
1838.
1840. // This code is governed by the BSD license found in the LICENSE file.
1841.
1842. /**
1843.  * If y is +0 and x is -0, Math.atan2(y,x) is an implementation-dependent approximation to +PI
1844.  *
1845.  * @path ch15/15.8/15.8.2/15.8.2.5/S15.8.2.5_A6.js
1846.  * @description Checking if Math.atan2(y,x) is an approximation to +PI, where y is +0 and x is -0
1847.  */
1848.
1849. \$INCLUDE("math_precision.js");
1850. \$INCLUDE("math_isequal.js");
1851.
1852. // CHECK#1
1853. //prec = 0.00000000000001;
1854. y = +0;
1855. x = -0;
1856. if (!isEqual(Math.atan2(y,x), Math.PI))
1857.     \$ERROR("#1: Math.abs(Math.atan2(" + y + ", -0) - Math.PI) >= " + prec);
1858.
1860. // This code is governed by the BSD license found in the LICENSE file.
1861.
1862. /**
1863.  * If y is equal to +0 and x<0, Math.atan2(y,x) is an implementation-dependent approximation to +PI
1864.  *
1865.  * @path ch15/15.8/15.8.2/15.8.2.5/S15.8.2.5_A7.js
1866.  * @description Checking if Math.atan2(y,x) is an approximation to +PI, where y is equal to +0 and x<0
1867.  */
1868.
1869. \$INCLUDE("math_precision.js");
1870. \$INCLUDE("math_isequal.js");
1871.
1872. // CHECK#1
1873. y = +0;
1874. //prec = 0.00000000000001;
1875. x = new Array();
1876. x[0] = -0.000000000000001;
1877. x[2] = -Infinity;
1878. x[1] = -1;
1879. xnum = 3;
1880.
1881. for (i = 0; i < xnum; i++)
1882. {
1883.     if (!isEqual(Math.atan2(y,x[i]), Math.PI))
1884.         \$FAIL("#1: Math.abs(Math.atan2(" + y + ", " + x[i] + ") - Math.PI) >= " + prec);
1885. }
1886.
1888. // This code is governed by the BSD license found in the LICENSE file.
1889.
1890. /**
1891.  * Cosine is a periodic function with period 2*PI
1892.  *
1893.  * @path ch15/15.8/15.8.2/15.8.2.7/S15.8.2.7_A6.js
1894.  * @description Checking if Math.cos(x) equals to Math.cos(x+n*2*Math.PI) with precision 0.000000000003, where n is an integer from 1 to 100 and x is one of 10 float point values from -Math.PI to +Math.PI
1895.  */
1896.
1897. // CHECK#1
1898.   prec = 0.000000000003;
1899. //prec = 0.000000000000001;
1900. period = 2*Math.PI;
1901. pernum = 100;
1902.
1903. a = -pernum * period;
1904. b = pernum * period;
1905. snum = 9;
1906. step = period/snum + 0.0;
1907. x = new Array();
1908. for (i = 0; i < snum; i++)
1909. {
1910.     x[i] = a + i*step;
1911. }
1912. x[9] = a + period;
1913.
1914. var curval;
1915. var curx;
1916. var j;
1917. for (i = 0; i < snum; i++)
1918. {
1919.     curval = Math.cos(x[i]);
1920.     curx = x[i] + period;
1921.     j = 0;
1922.     while (curx <= b)
1923.     {
1924.         curx += period;
1925.         j++;
1926.         if (Math.abs(Math.cos(curx) - curval) >= prec)
1927.         {
1928.             \$FAIL("#1: cos is found out to not be periodic:\n Math.abs(Math.cos(" + x[i] + ") - Math.cos(" + x[i] + " + 2*Math.PI*" + j + ")) >= " + prec + "\n Math.cos(" + x[i] + ") === " + curval + "\n Math.cos(" + curx + ") === " + Math.cos(curx));
1929.         }
1930.     }
1931. }
1932.
1934. // This code is governed by the BSD license found in the LICENSE file.
1935.
1936. /**
1937.  * Math.cos it is recommended that implementations use the approximation algorithms for IEEE 754 arithmetic contained in fdlibm
1938.  *
1939.  * @path ch15/15.8/15.8.2/15.8.2.7/S15.8.2.7_A7.js
1940.  * @description Checking if Math.cos is approximately equals to its mathematical values on the set of 64 argument values; all the sample values is calculated with LibC
1941.  */
1942.
1943. \$INCLUDE("math_precision.js");
1944. \$INCLUDE("math_isequal.js");
1945.
1946. // CHECK#1
1947. vnum = 64;
1948. var x = new Array();
1949. x[0] = -3.14159265358979310000;
1950. x[1] = -3.04185955347583150000;
1951. x[2] = -2.94212645336186980000;
1952. x[3] = -2.84239335324790820000;
1953. x[4] = -2.74266025313394660000;
1954. x[5] = -2.64292715301998450000;
1955. x[6] = -2.54319405290602290000;
1956. x[7] = -2.44346095279206120000;
1957. x[8] = -2.34372785267809960000;
1958. x[9] = -2.24399475256413790000;
1959. x[10] = -2.14426165245017630000;
1960. x[11] = -2.04452855233621470000;
1961. x[12] = -1.94479545222225280000;
1962. x[13] = -1.84506235210829120000;
1963. x[14] = -1.74532925199432950000;
1964. x[15] = -1.64559615188036790000;
1965. x[16] = -1.54586305176640600000;
1966. x[17] = -1.44612995165244440000;
1967. x[18] = -1.34639685153848280000;
1968. x[19] = -1.24666375142452110000;
1969. x[20] = -1.14693065131055950000;
1970. x[21] = -1.04719755119659740000;
1971. x[22] = -0.94746445108263622000;
1972. x[23] = -0.84773135096867458000;
1973. x[24] = -0.74799825085471250000;
1974. x[25] = -0.64826515074075086000;
1975. x[26] = -0.54853205062678922000;
1976. x[27] = -0.44879895051282759000;
1977. x[28] = -0.34906585039886595000;
1978. x[29] = -0.24933275028490431000;
1979. x[30] = -0.14959965017094268000;
1980. x[31] = -0.04986655005698104000;
1981. x[32] = 0.04986655005698104000;
1982. x[33] = 0.14959965017094268000;
1983. x[34] = 0.24933275028490431000;
1984. x[35] = 0.34906585039886595000;
1985. x[36] = 0.44879895051282759000;
1986. x[37] = 0.54853205062678922000;
1987. x[38] = 0.64826515074075086000;
1988. x[39] = 0.74799825085471250000;
1989. x[40] = 0.84773135096867414000;
1990. x[41] = 0.94746445108263533000;
1991. x[42] = 1.04719755119659830000;
1992. x[43] = 1.14693065131055950000;
1993. x[44] = 1.24666375142452070000;
1994. x[45] = 1.34639685153848280000;
1995. x[46] = 1.44612995165244400000;
1996. x[47] = 1.54586305176640600000;
1997. x[48] = 1.64559615188036810000;
1998. x[49] = 1.74532925199432930000;
1999. x[50] = 1.84506235210829140000;
2000. x[51] = 1.94479545222225260000;
2001. x[52] = 2.04452855233621470000;
2002. x[53] = 2.14426165245017670000;
2003. x[54] = 2.24399475256413790000;
2004. x[55] = 2.34372785267810000000;
2005. x[56] = 2.44346095279206120000;
2006. x[57] = 2.54319405290602240000;
2007. x[58] = 2.64292715301998450000;
2008. x[59] = 2.74266025313394660000;
2009. x[60] = 2.84239335324790780000;
2010. x[61] = 2.94212645336186980000;
2011. x[62] = 3.04185955347583100000;
2012. x[63] = 3.14159265358979310000;
2013.
2014.
2015. var y = new Array();
2016. y[0] = -1.00000000000000000000;
2017. y[1] = -0.99503077536540141000;
2018. y[2] = -0.98017248784854383000;
2019. y[3] = -0.95557280578614079000;
2020. y[4] = -0.92147621187040774000;
2021. y[5] = -0.87822157337022844000;
2022. y[6] = -0.82623877431599468000;
2023. y[7] = -0.76604444311897790000;
2024. y[8] = -0.69823681808607274000;
2025. y[9] = -0.62348980185873348000;
2026. y[10] = -0.54254626386575933000;
2027. y[11] = -0.45621065735316296000;
2028. y[12] = -0.36534102436639487000;
2029. y[13] = -0.27084046814300500000;
2030. y[14] = -0.17364817766693030000;
2031. y[15] = -0.07473009358642426800;
2032. y[16] = 0.02493069173807303500;
2033. y[17] = 0.12434370464748527000;
2034. y[18] = 0.22252093395631445000;
2035. y[19] = 0.31848665025168443000;
2036. y[20] = 0.41128710313061151000;
2037. y[21] = 0.50000000000000033000;
2038. y[22] = 0.58374367223478973000;
2039. y[23] = 0.66168583759685928000;
2040. y[24] = 0.73305187182982645000;
2041. y[25] = 0.79713250722292250000;
2042. y[26] = 0.85329088163215572000;
2043. y[27] = 0.90096886790241915000;
2044. y[28] = 0.93969262078590832000;
2045. y[29] = 0.96907728622907796000;
2046. y[30] = 0.98883082622512852000;
2047. y[31] = 0.99875692121892234000;
2048. y[32] = 0.99875692121892234000;
2049. y[33] = 0.98883082622512852000;
2050. y[34] = 0.96907728622907796000;
2051. y[35] = 0.93969262078590832000;
2052. y[36] = 0.90096886790241915000;
2053. y[37] = 0.85329088163215572000;
2054. y[38] = 0.79713250722292250000;
2055. y[39] = 0.73305187182982645000;
2056. y[40] = 0.66168583759685962000;
2057. y[41] = 0.58374367223479051000;
2058. y[42] = 0.49999999999999950000;
2059. y[43] = 0.41128710313061151000;
2060. y[44] = 0.31848665025168482000;
2061. y[45] = 0.22252093395631445000;
2062. y[46] = 0.12434370464748572000;
2063. y[47] = 0.02493069173807303500;
2064. y[48] = -0.07473009358642449000;
2065. y[49] = -0.17364817766693008000;
2066. y[50] = -0.27084046814300522000;
2067. y[51] = -0.36534102436639465000;
2068. y[52] = -0.45621065735316296000;
2069. y[53] = -0.54254626386575977000;
2070. y[54] = -0.62348980185873348000;
2071. y[55] = -0.69823681808607307000;
2072. y[56] = -0.76604444311897790000;
2073. y[57] = -0.82623877431599446000;
2074. y[58] = -0.87822157337022844000;
2075. y[59] = -0.92147621187040774000;
2076. y[60] = -0.95557280578614057000;
2077. y[61] = -0.98017248784854383000;
2078. y[62] = -0.99503077536540141000;
2079. y[63] = -1.00000000000000000000;
2080.
2081.
2082. var val;
2083. for (i = 0; i < vnum; i++)
2084. {
2085.     val = Math.cos(x[i]);
2086.     if (!isEqual(val, y[i]))
2087.     {
2088.         \$ERROR("\nx = " + x[i] + "\nlibc.cos(x) = " + y[i] + "\nMath.cos(x) = " + Math.cos(x[i]) + "\nMath.abs(libc.cos(x) - Math.cos(x)) > " + prec + "\n\n");
2089.     }
2090. }
2091.
2093. // This code is governed by the BSD license found in the LICENSE file.
2094.
2095. /**
2096.  * Number type represented as the double precision 64-bit format IEEE 754
2097.  *
2098.  * @path ch08/8.5/S8.5_A2.1.js
2099.  * @description Use 2^53 + 2 number and do some operation with it
2100.  */
2101.
2102. var x = 9007199254740994.0; /* 2^53 + 2 */
2103. var y = 1.0 - 1/65536.0;
2104. var z = x + y;
2105. var d = z - x;
2106.
2107. if (d !== 0){
2108.   \$ERROR('#1: var x = 9007199254740994.0; var y = 1.0 - 1/65536.0; var z = x + y; var d = z - x; d === 0. Actual: ' + (d));
2109. }
2110.
2112. // This code is governed by the BSD license found in the LICENSE file.
2113.
2114. /**
2115.  * Number type represented as the extended precision 64-bit format IEEE 754
2116.  *
2117.  * @path ch08/8.5/S8.5_A2.2.js
2118.  * @description Use 2^53 + 2 number and do some operation with it
2119.  */
2120.
2121. var x = 9007199254740994.0; /* 2^53 + 2 */
2122. var y = 1.0 - 1/65536.0;
2123. var z = x + y;
2124. var d = z - x;
2125.
2126. if (d === 2){
2127.   \$ERROR('#1: var x = 9007199254740994.0; var y = 1.0 - 1/65536.0; var z = x + y; var d = z - x; d !== 2');
2128. }