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

Side by Side Diff: src/math.js

Issue 68453005: Use %_IsMinusZero where applicable to replace hackery. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 1 month 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 | « src/i18n.js ('k') | src/runtime.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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 110
111 // ECMA 262 - 15.8.2.11 111 // ECMA 262 - 15.8.2.11
112 function MathMax(arg1, arg2) { // length == 2 112 function MathMax(arg1, arg2) { // length == 2
113 var length = %_ArgumentsLength(); 113 var length = %_ArgumentsLength();
114 if (length == 2) { 114 if (length == 2) {
115 arg1 = TO_NUMBER_INLINE(arg1); 115 arg1 = TO_NUMBER_INLINE(arg1);
116 arg2 = TO_NUMBER_INLINE(arg2); 116 arg2 = TO_NUMBER_INLINE(arg2);
117 if (arg2 > arg1) return arg2; 117 if (arg2 > arg1) return arg2;
118 if (arg1 > arg2) return arg1; 118 if (arg1 > arg2) return arg1;
119 if (arg1 == arg2) { 119 if (arg1 == arg2) {
120 // Make sure -0 is considered less than +0. -0 is never a Smi, +0 can be 120 // Make sure -0 is considered less than +0.
121 // a Smi or a heap number. 121 return (arg1 === 0 && %_IsMinusZero(arg1)) ? arg2 : arg1;
122 return (arg1 == 0 && !%_IsSmi(arg1) && 1 / arg1 < 0) ? arg2 : arg1;
123 } 122 }
124 // All comparisons failed, one of the arguments must be NaN. 123 // All comparisons failed, one of the arguments must be NaN.
125 return NAN; 124 return NAN;
126 } 125 }
127 var r = -INFINITY; 126 var r = -INFINITY;
128 for (var i = 0; i < length; i++) { 127 for (var i = 0; i < length; i++) {
129 var n = %_Arguments(i); 128 var n = %_Arguments(i);
130 if (!IS_NUMBER(n)) n = NonNumberToNumber(n); 129 if (!IS_NUMBER(n)) n = NonNumberToNumber(n);
131 // Make sure +0 is considered greater than -0. -0 is never a Smi, +0 can be 130 // Make sure +0 is considered greater than -0.
132 // a Smi or heap number. 131 if (NUMBER_IS_NAN(n) || n > r || (r === 0 && n === 0 && %_IsMinusZero(r))) {
133 if (NUMBER_IS_NAN(n) || n > r ||
134 (r == 0 && n == 0 && !%_IsSmi(r) && 1 / r < 0)) {
135 r = n; 132 r = n;
136 } 133 }
137 } 134 }
138 return r; 135 return r;
139 } 136 }
140 137
141 // ECMA 262 - 15.8.2.12 138 // ECMA 262 - 15.8.2.12
142 function MathMin(arg1, arg2) { // length == 2 139 function MathMin(arg1, arg2) { // length == 2
143 var length = %_ArgumentsLength(); 140 var length = %_ArgumentsLength();
144 if (length == 2) { 141 if (length == 2) {
145 arg1 = TO_NUMBER_INLINE(arg1); 142 arg1 = TO_NUMBER_INLINE(arg1);
146 arg2 = TO_NUMBER_INLINE(arg2); 143 arg2 = TO_NUMBER_INLINE(arg2);
147 if (arg2 > arg1) return arg1; 144 if (arg2 > arg1) return arg1;
148 if (arg1 > arg2) return arg2; 145 if (arg1 > arg2) return arg2;
149 if (arg1 == arg2) { 146 if (arg1 == arg2) {
150 // Make sure -0 is considered less than +0. -0 is never a Smi, +0 can be 147 // Make sure -0 is considered less than +0.
151 // a Smi or a heap number. 148 return (arg1 === 0 && %_IsMinusZero(arg1)) ? arg1 : arg2;
152 return (arg1 == 0 && !%_IsSmi(arg1) && 1 / arg1 < 0) ? arg1 : arg2;
153 } 149 }
154 // All comparisons failed, one of the arguments must be NaN. 150 // All comparisons failed, one of the arguments must be NaN.
155 return NAN; 151 return NAN;
156 } 152 }
157 var r = INFINITY; 153 var r = INFINITY;
158 for (var i = 0; i < length; i++) { 154 for (var i = 0; i < length; i++) {
159 var n = %_Arguments(i); 155 var n = %_Arguments(i);
160 if (!IS_NUMBER(n)) n = NonNumberToNumber(n); 156 if (!IS_NUMBER(n)) n = NonNumberToNumber(n);
161 // Make sure -0 is considered less than +0. -0 is never a Smi, +0 can be a 157 // Make sure -0 is considered less than +0.
162 // Smi or a heap number. 158 if (NUMBER_IS_NAN(n) || n < r || (r === 0 && n === 0 && %_IsMinusZero(n))) {
163 if (NUMBER_IS_NAN(n) || n < r ||
164 (r == 0 && n == 0 && !%_IsSmi(n) && 1 / n < 0)) {
165 r = n; 159 r = n;
166 } 160 }
167 } 161 }
168 return r; 162 return r;
169 } 163 }
170 164
171 // ECMA 262 - 15.8.2.13 165 // ECMA 262 - 15.8.2.13
172 function MathPow(x, y) { 166 function MathPow(x, y) {
173 return %_MathPow(TO_NUMBER_INLINE(x), TO_NUMBER_INLINE(y)); 167 return %_MathPow(TO_NUMBER_INLINE(x), TO_NUMBER_INLINE(y));
174 } 168 }
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 "tan", MathTan, 266 "tan", MathTan,
273 "atan2", MathAtan2, 267 "atan2", MathAtan2,
274 "pow", MathPow, 268 "pow", MathPow,
275 "max", MathMax, 269 "max", MathMax,
276 "min", MathMin, 270 "min", MathMin,
277 "imul", MathImul 271 "imul", MathImul
278 )); 272 ));
279 } 273 }
280 274
281 SetUpMath(); 275 SetUpMath();
OLDNEW
« no previous file with comments | « src/i18n.js ('k') | src/runtime.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698