OLD | NEW |
1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 30 matching lines...) Expand all Loading... |
41 | 41 |
42 function run_tests_for(divisor) { | 42 function run_tests_for(divisor) { |
43 print("(function(left) { return left / " + divisor + "; })"); | 43 print("(function(left) { return left / " + divisor + "; })"); |
44 var div_func = this.eval("(function(left) { return left / " + divisor + "; })"
); | 44 var div_func = this.eval("(function(left) { return left / " + divisor + "; })"
); |
45 var mod_func = this.eval("(function(left) { return left % " + divisor + "; })"
); | 45 var mod_func = this.eval("(function(left) { return left % " + divisor + "; })"
); |
46 var exp; | 46 var exp; |
47 // Strange number test. | 47 // Strange number test. |
48 divmod(div_func, mod_func, 0, divisor); | 48 divmod(div_func, mod_func, 0, divisor); |
49 divmod(div_func, mod_func, 1 / 0, divisor); | 49 divmod(div_func, mod_func, 1 / 0, divisor); |
50 // Floating point number test. | 50 // Floating point number test. |
51 for (exp = -1024; exp <= 1024; exp += 4) { | 51 for (exp = -1024; exp <= 1024; exp += 8) { |
52 divmod(div_func, mod_func, Math.pow(2, exp), divisor); | 52 divmod(div_func, mod_func, Math.pow(2, exp), divisor); |
53 divmod(div_func, mod_func, 0.9999999 * Math.pow(2, exp), divisor); | 53 divmod(div_func, mod_func, 0.9999999 * Math.pow(2, exp), divisor); |
54 divmod(div_func, mod_func, 1.0000001 * Math.pow(2, exp), divisor); | 54 divmod(div_func, mod_func, 1.0000001 * Math.pow(2, exp), divisor); |
55 } | 55 } |
56 // Integer number test. | 56 // Integer number test. |
57 for (exp = 0; exp <= 32; exp++) { | 57 for (exp = 0; exp <= 32; exp++) { |
58 divmod(div_func, mod_func, 1 << exp, divisor); | 58 divmod(div_func, mod_func, 1 << exp, divisor); |
59 divmod(div_func, mod_func, (1 << exp) + 1, divisor); | 59 divmod(div_func, mod_func, (1 << exp) + 1, divisor); |
60 divmod(div_func, mod_func, (1 << exp) - 1, divisor); | 60 divmod(div_func, mod_func, (1 << exp) - 1, divisor); |
61 } | 61 } |
62 divmod(div_func, mod_func, Math.floor(0x1fffffff / 3), divisor); | 62 divmod(div_func, mod_func, Math.floor(0x1fffffff / 3), divisor); |
63 divmod(div_func, mod_func, Math.floor(-0x20000000 / 3), divisor); | 63 divmod(div_func, mod_func, Math.floor(-0x20000000 / 3), divisor); |
64 } | 64 } |
65 | 65 |
66 | 66 |
67 var divisors = [ | 67 var divisors = [ |
68 0, | 68 0, |
69 1, | 69 1, |
70 2, | 70 2, |
71 3, | 71 3, |
72 4, | 72 4, |
73 5, | 73 5, |
74 6, | 74 6, |
75 7, | 75 7, |
76 8, | 76 8, |
77 9, | 77 9, |
78 10, | 78 10, |
79 // These ones in the middle don't add much apart from slowness to the test. | |
80 0x1000000, | 79 0x1000000, |
81 0x2000000, | |
82 0x4000000, | |
83 0x8000000, | |
84 0x10000000, | |
85 0x20000000, | |
86 0x40000000, | 80 0x40000000, |
87 12, | 81 12, |
88 60, | 82 60, |
89 100, | 83 100, |
90 1000 * 60 * 60 * 24]; | 84 1000 * 60 * 60 * 24]; |
91 | 85 |
92 for (var i = 0; i < divisors.length; i++) { | 86 for (var i = 0; i < divisors.length; i++) { |
93 run_tests_for(divisors[i]); | 87 run_tests_for(divisors[i]); |
94 } | 88 } |
95 | |
OLD | NEW |