|
1 // Copyright 2009 the Sputnik authors. All rights reserved. |
|
2 // This code is governed by the BSD license found in the LICENSE file. |
|
3 |
|
4 /** |
|
5 * The result of a ECMAScript floating-point remainder operation is determined by the rules of IEEE arithmetics |
|
6 * |
|
7 * @path ch11/11.5/11.5.3/S11.5.3_A4_T7.js |
|
8 * @description If operands neither an infinity, nor a zero, nor NaN, return x - truncate(x / y) * y |
|
9 */ |
|
10 |
|
11 function truncate(x) { |
|
12 if (x > 0) { |
|
13 return Math.floor(x); |
|
14 } else { |
|
15 return Math.ceil(x); |
|
16 } |
|
17 } |
|
18 |
|
19 //CHECK#1 |
|
20 x = 1.3; |
|
21 y = 1.1; |
|
22 if (x % y !== 0.19999999999999996) { |
|
23 $ERROR('#1: x = 1.3; y = 1.1; x % y === 0.19999999999999996. Actual: ' + (x % y)); |
|
24 } |
|
25 |
|
26 //CHECK#2 |
|
27 x = -1.3; |
|
28 y = 1.1; |
|
29 if (x % y !== -0.19999999999999996) { |
|
30 $ERROR('#2: x = -1.3; y = 1.1; x % y === -0.19999999999999996. Actual: ' + (x % y)); |
|
31 } |
|
32 |
|
33 //CHECK#3 |
|
34 x = 1.3; |
|
35 y = -1.1; |
|
36 if (x % y !== 0.19999999999999996) { |
|
37 $ERROR('#3: x = 1.3; y = -1.1; x % y === 0.19999999999999996. Actual: ' + (x % y)); |
|
38 } |
|
39 |
|
40 //CHECK#4 |
|
41 x = -1.3; |
|
42 y = -1.1; |
|
43 if (x % y !== -0.19999999999999996) { |
|
44 $ERROR('#4: x = -1.3; y = -1.1; x % y === -0.19999999999999996. Actual: ' + (x % y)); |
|
45 } |
|
46 |
|
47 //CHECK#5 |
|
48 x = 1.3; |
|
49 y = 1.1; |
|
50 if (x % y !== x - truncate(x / y) * y) { |
|
51 $ERROR('#5: x = 1.3; y = 1.1; x % y === x - truncate(x / y) * y. Actual: ' + (x % y)); |
|
52 } |
|
53 |
|
54 //CHECK#6 |
|
55 x = -1.3; |
|
56 y = 1.1; |
|
57 if (x % y !== x - truncate(x / y) * y) { |
|
58 $ERROR('#6: x = -1.3; y = 1.1; x % y === x - truncate(x / y) * y. Actual: ' + (x % y)); |
|
59 } |
|
60 |
|
61 //CHECK#7 |
|
62 x = 1.3; |
|
63 y = -1.1; |
|
64 if (x % y !== x - truncate(x / y) * y) { |
|
65 $ERROR('#7: x = 1.3; y = -1.1; x % y === x - truncate(x / y) * y. Actual: ' + (x % y)); |
|
66 } |
|
67 |
|
68 //CHECK#8 |
|
69 x = -1.3; |
|
70 y = -1.1; |
|
71 if (x % y !== x - truncate(x / y) * y) { |
|
72 $ERROR('#8: x = -1.3; y = -1.1; x % y === x - truncate(x / y) * y. Actual: ' + (x % y)); |
|
73 } |
|
74 |