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

Side by Side Diff: test/mjsunit/math-floor.js

Issue 11035053: Rollback trunk to bleeding_edge revision 12525 (Closed) Base URL: https://v8.googlecode.com/svn/trunk
Patch Set: Created 8 years, 2 months 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/limit-locals.js ('k') | test/mjsunit/math-floor-part1.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 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 27 matching lines...) Expand all
38 %OptimizeFunctionOnNextCall(test); 38 %OptimizeFunctionOnNextCall(test);
39 assertEquals(expect, test(input)); 39 assertEquals(expect, test(input));
40 } 40 }
41 41
42 function zero() { 42 function zero() {
43 var x = 0.5; 43 var x = 0.5;
44 return (function() { return x - 0.5; })(); 44 return (function() { return x - 0.5; })();
45 } 45 }
46 46
47 function test() { 47 function test() {
48 testFloor(0, 0);
49 testFloor(0, zero());
50 testFloor(-0, -0);
51 testFloor(Infinity, Infinity);
52 testFloor(-Infinity, -Infinity);
53 testFloor(NaN, NaN);
54
48 // Ensure that a negative zero coming from Math.floor is properly handled 55 // Ensure that a negative zero coming from Math.floor is properly handled
49 // by other operations. 56 // by other operations.
50 function ifloor(x) { 57 function ifloor(x) {
51 return 1 / Math.floor(x); 58 return 1 / Math.floor(x);
52 } 59 }
53 assertEquals(-Infinity, ifloor(-0)); 60 assertEquals(-Infinity, ifloor(-0));
54 assertEquals(-Infinity, ifloor(-0)); 61 assertEquals(-Infinity, ifloor(-0));
55 assertEquals(-Infinity, ifloor(-0)); 62 assertEquals(-Infinity, ifloor(-0));
56 %OptimizeFunctionOnNextCall(ifloor); 63 %OptimizeFunctionOnNextCall(ifloor);
57 assertEquals(-Infinity, ifloor(-0)); 64 assertEquals(-Infinity, ifloor(-0));
(...skipping 14 matching lines...) Expand all
72 testFloor(-2, -1.1); 79 testFloor(-2, -1.1);
73 testFloor(-2, -1.5); 80 testFloor(-2, -1.5);
74 testFloor(-2, -1.7); 81 testFloor(-2, -1.7);
75 82
76 testFloor(0, Number.MIN_VALUE); 83 testFloor(0, Number.MIN_VALUE);
77 testFloor(-1, -Number.MIN_VALUE); 84 testFloor(-1, -Number.MIN_VALUE);
78 testFloor(Number.MAX_VALUE, Number.MAX_VALUE); 85 testFloor(Number.MAX_VALUE, Number.MAX_VALUE);
79 testFloor(-Number.MAX_VALUE, -Number.MAX_VALUE); 86 testFloor(-Number.MAX_VALUE, -Number.MAX_VALUE);
80 testFloor(Infinity, Infinity); 87 testFloor(Infinity, Infinity);
81 testFloor(-Infinity, -Infinity); 88 testFloor(-Infinity, -Infinity);
89
90 // 2^30 is a smi boundary.
91 var two_30 = 1 << 30;
92
93 testFloor(two_30, two_30);
94 testFloor(two_30, two_30 + 0.1);
95 testFloor(two_30, two_30 + 0.5);
96 testFloor(two_30, two_30 + 0.7);
97
98 testFloor(two_30 - 1, two_30 - 1);
99 testFloor(two_30 - 1, two_30 - 1 + 0.1);
100 testFloor(two_30 - 1, two_30 - 1 + 0.5);
101 testFloor(two_30 - 1, two_30 - 1 + 0.7);
102
103 testFloor(-two_30, -two_30);
104 testFloor(-two_30, -two_30 + 0.1);
105 testFloor(-two_30, -two_30 + 0.5);
106 testFloor(-two_30, -two_30 + 0.7);
107
108 testFloor(-two_30 + 1, -two_30 + 1);
109 testFloor(-two_30 + 1, -two_30 + 1 + 0.1);
110 testFloor(-two_30 + 1, -two_30 + 1 + 0.5);
111 testFloor(-two_30 + 1, -two_30 + 1 + 0.7);
112
113 // 2^52 is a precision boundary.
114 var two_52 = (1 << 30) * (1 << 22);
115
116 testFloor(two_52, two_52);
117 testFloor(two_52, two_52 + 0.1);
118 assertEquals(two_52, two_52 + 0.5);
119 testFloor(two_52, two_52 + 0.5);
120 assertEquals(two_52 + 1, two_52 + 0.7);
121 testFloor(two_52 + 1, two_52 + 0.7);
122
123 testFloor(two_52 - 1, two_52 - 1);
124 testFloor(two_52 - 1, two_52 - 1 + 0.1);
125 testFloor(two_52 - 1, two_52 - 1 + 0.5);
126 testFloor(two_52 - 1, two_52 - 1 + 0.7);
127
128 testFloor(-two_52, -two_52);
129 testFloor(-two_52, -two_52 + 0.1);
130 testFloor(-two_52, -two_52 + 0.5);
131 testFloor(-two_52, -two_52 + 0.7);
132
133 testFloor(-two_52 + 1, -two_52 + 1);
134 testFloor(-two_52 + 1, -two_52 + 1 + 0.1);
135 testFloor(-two_52 + 1, -two_52 + 1 + 0.5);
136 testFloor(-two_52 + 1, -two_52 + 1 + 0.7);
82 } 137 }
83 138
84 139
85 // Test in a loop to cover the custom IC and GC-related issues. 140 // Test in a loop to cover the custom IC and GC-related issues.
86 for (var i = 0; i < 100; i++) { 141 for (var i = 0; i < 500; i++) {
87 test(); 142 test();
88 } 143 }
144
145
146 // Regression test for a bug where a negative zero coming from Math.floor
147 // was not properly handled by other operations.
148 function floorsum(i, n) {
149 var ret = Math.floor(n);
150 while (--i > 0) {
151 ret += Math.floor(n);
152 }
153 return ret;
154 }
155 assertEquals(-0, floorsum(1, -0));
156 %OptimizeFunctionOnNextCall(floorsum);
157 // The optimized function will deopt. Run it with enough iterations to try
158 // to optimize via OSR (triggering the bug).
159 assertEquals(-0, floorsum(100000, -0));
OLDNEW
« no previous file with comments | « test/mjsunit/limit-locals.js ('k') | test/mjsunit/math-floor-part1.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698