Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(110)

Side by Side Diff: test/mjsunit/div-mod.js

Issue 8888006: Make more JS files beter match the coding standard. Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Address review comments Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « test/mjsunit/debug-version.js ('k') | test/mjsunit/elements-kind.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 25 matching lines...) Expand all
36 assertEquals(x % y, mod_answer, x + "%" + y); 36 assertEquals(x % y, mod_answer, x + "%" + y);
37 var minus_div_answer = (div_func)(-x); 37 var minus_div_answer = (div_func)(-x);
38 assertEquals(-x / y, minus_div_answer, "-" + x + "/" + y); 38 assertEquals(-x / y, minus_div_answer, "-" + x + "/" + y);
39 var minus_mod_answer = (mod_func)(-x); 39 var minus_mod_answer = (mod_func)(-x);
40 assertEquals(-x % y, minus_mod_answer, "-" + x + "%" + y); 40 assertEquals(-x % y, minus_mod_answer, "-" + x + "%" + y);
41 } 41 }
42 42
43 43
44 function run_tests_for(divisor) { 44 function run_tests_for(divisor) {
45 print("(function(left) { return left / " + divisor + "; })"); 45 print("(function(left) { return left / " + divisor + "; })");
46 var div_func = this.eval("(function(left) { return left / " + divisor + "; })" ); 46 var div_func =
47 var mod_func = this.eval("(function(left) { return left % " + divisor + "; })" ); 47 this.eval("(function(left) { return left / " + divisor + "; })");
48 var mod_func =
49 this.eval("(function(left) { return left % " + divisor + "; })");
48 var exp; 50 var exp;
49 // Strange number test. 51 // Strange number test.
50 divmod(div_func, mod_func, 0, divisor); 52 divmod(div_func, mod_func, 0, divisor);
51 divmod(div_func, mod_func, 1 / 0, divisor); 53 divmod(div_func, mod_func, 1 / 0, divisor);
52 // Floating point number test. 54 // Floating point number test.
53 for (exp = -1024; exp <= 1024; exp += 8) { 55 for (exp = -1024; exp <= 1024; exp += 8) {
54 divmod(div_func, mod_func, Math.pow(2, exp), divisor); 56 divmod(div_func, mod_func, Math.pow(2, exp), divisor);
55 divmod(div_func, mod_func, 0.9999999 * Math.pow(2, exp), divisor); 57 divmod(div_func, mod_func, 0.9999999 * Math.pow(2, exp), divisor);
56 divmod(div_func, mod_func, 1.0000001 * Math.pow(2, exp), divisor); 58 divmod(div_func, mod_func, 1.0000001 * Math.pow(2, exp), divisor);
57 } 59 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 } 92 }
91 93
92 // Test extreme corner cases of modulo. 94 // Test extreme corner cases of modulo.
93 95
94 // Computes the modulo by slow but lossless operations. 96 // Computes the modulo by slow but lossless operations.
95 function compute_mod(dividend, divisor) { 97 function compute_mod(dividend, divisor) {
96 // Return NaN if either operand is NaN, if divisor is 0 or 98 // Return NaN if either operand is NaN, if divisor is 0 or
97 // dividend is an infinity. Return dividend if divisor is an infinity. 99 // dividend is an infinity. Return dividend if divisor is an infinity.
98 if (isNaN(dividend) || isNaN(divisor) || divisor == 0) { return NaN; } 100 if (isNaN(dividend) || isNaN(divisor) || divisor == 0) { return NaN; }
99 var sign = 1; 101 var sign = 1;
100 if (dividend < 0) { dividend = -dividend; sign = -1; } 102 if (dividend < 0) {
103 dividend = -dividend;
104 sign = -1;
105 }
101 if (dividend == Infinity) { return NaN; } 106 if (dividend == Infinity) { return NaN; }
102 if (divisor < 0) { divisor = -divisor; } 107 if (divisor < 0) { divisor = -divisor; }
103 if (divisor == Infinity) { return sign * dividend; } 108 if (divisor == Infinity) { return sign * dividend; }
104 function rec_mod(a, b) { 109 function rec_mod(a, b) {
105 // Subtracts maximal possible multiplum of b from a. 110 // Subtracts maximal possible multiplum of b from a.
106 if (a >= b) { 111 if (a >= b) {
107 a = rec_mod(a, 2 * b); 112 a = rec_mod(a, 2 * b);
108 if (a >= b) { a -= b; } 113 if (a >= b) { a -= b; }
109 } 114 }
110 return a; 115 return a;
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 function lithium_integer_mod() { 202 function lithium_integer_mod() {
198 var left_operands = [ 203 var left_operands = [
199 0, 204 0,
200 305419896, // 0x12345678 205 305419896, // 0x12345678
201 ]; 206 ];
202 207
203 // Test the standard lithium code for modulo opeartions. 208 // Test the standard lithium code for modulo opeartions.
204 var mod_func; 209 var mod_func;
205 for (var i = 0; i < left_operands.length; i++) { 210 for (var i = 0; i < left_operands.length; i++) {
206 for (var j = 0; j < divisors.length; j++) { 211 for (var j = 0; j < divisors.length; j++) {
207 mod_func = this.eval("(function(left) { return left % " + divisors[j]+ "; })"); 212 mod_func =
208 assertEquals((mod_func)(left_operands[i]), left_operands[i] % divisors[j]) ; 213 this.eval("(function(left) { return left % " + divisors[j]+ "; })");
209 assertEquals((mod_func)(-left_operands[i]), -left_operands[i] % divisors[j ]); 214 assertEquals((mod_func)(left_operands[i]),
215 left_operands[i] % divisors[j]);
216 assertEquals((mod_func)(-left_operands[i]),
217 -left_operands[i] % divisors[j]);
210 } 218 }
211 } 219 }
212 220
213 var results_powers_of_two = [ 221 var results_powers_of_two = [
214 // 0 222 // 0
215 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 223 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
224 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
225 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
226 0],
216 // 305419896 == 0x12345678 227 // 305419896 == 0x12345678
217 [0, 0, 0, 8, 24, 56, 120, 120, 120, 632, 1656, 1656, 5752, 5752, 22136, 2213 6, 22136, 22136, 284280, 284280, 1332856, 3430008, 3430008, 3430008, 3430008, 36 984440, 36984440, 36984440, 305419896, 305419896, 305419896], 228 [0, 0, 0, 8, 24, 56, 120, 120, 120, 632,
229 1656, 1656, 5752, 5752, 22136, 22136, 22136, 22136, 284280, 284280,
230 1332856, 3430008, 3430008, 3430008, 3430008,
231 36984440, 36984440, 36984440, 305419896, 305419896,
232 305419896],
218 ]; 233 ];
219 234
220 // Test the lithium code for modulo operations with a variable power of two 235 // Test the lithium code for modulo operations with a variable power of two
221 // right hand side operand. 236 // right hand side operand.
222 for (var i = 0; i < left_operands.length; i++) { 237 for (var i = 0; i < left_operands.length; i++) {
223 for (var j = 0; j < 31; j++) { 238 for (var j = 0; j < 31; j++) {
224 assertEquals(results_powers_of_two[i][j], left_operands[i] % (2 << j)); 239 assertEquals(results_powers_of_two[i][j], left_operands[i] % (2 << j));
225 assertEquals(results_powers_of_two[i][j], left_operands[i] % -(2 << j)); 240 assertEquals(results_powers_of_two[i][j], left_operands[i] % -(2 << j));
226 assertEquals(-results_powers_of_two[i][j], -left_operands[i] % (2 << j)); 241 assertEquals(-results_powers_of_two[i][j], -left_operands[i] % (2 << j));
227 assertEquals(-results_powers_of_two[i][j], -left_operands[i] % -(2 << j)); 242 assertEquals(-results_powers_of_two[i][j], -left_operands[i] % -(2 << j));
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 assertEquals(-results_powers_of_two[i][26], -left_operands[i] % -(2 << 26)); 308 assertEquals(-results_powers_of_two[i][26], -left_operands[i] % -(2 << 26));
294 assertEquals(-results_powers_of_two[i][27], -left_operands[i] % (2 << 27)); 309 assertEquals(-results_powers_of_two[i][27], -left_operands[i] % (2 << 27));
295 assertEquals(-results_powers_of_two[i][28], -left_operands[i] % -(2 << 28)); 310 assertEquals(-results_powers_of_two[i][28], -left_operands[i] % -(2 << 28));
296 assertEquals(-results_powers_of_two[i][29], -left_operands[i] % (2 << 29)); 311 assertEquals(-results_powers_of_two[i][29], -left_operands[i] % (2 << 29));
297 assertEquals(-results_powers_of_two[i][30], -left_operands[i] % -(2 << 30)); 312 assertEquals(-results_powers_of_two[i][30], -left_operands[i] % -(2 << 30));
298 } 313 }
299 314
300 } 315 }
301 316
302 lithium_integer_mod(); 317 lithium_integer_mod();
303 %OptimizeFunctionOnNextCall(lithium_integer_mod) 318 %OptimizeFunctionOnNextCall(lithium_integer_mod);
304 lithium_integer_mod(); 319 lithium_integer_mod();
OLDNEW
« no previous file with comments | « test/mjsunit/debug-version.js ('k') | test/mjsunit/elements-kind.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698