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

Side by Side Diff: src/math.js

Issue 504343005: Slightly simplify Math.sign and Math.trunc. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 3 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 | « no previous file | no next file » | 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 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 "use strict"; 5 "use strict";
6 6
7 // This file relies on the fact that the following declarations have been made 7 // This file relies on the fact that the following declarations have been made
8 // in runtime.js: 8 // in runtime.js:
9 // var $Object = global.Object; 9 // var $Object = global.Object;
10 10
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 // Non-standard extension. 166 // Non-standard extension.
167 function MathImul(x, y) { 167 function MathImul(x, y) {
168 return %NumberImul(TO_NUMBER_INLINE(x), TO_NUMBER_INLINE(y)); 168 return %NumberImul(TO_NUMBER_INLINE(x), TO_NUMBER_INLINE(y));
169 } 169 }
170 170
171 // ES6 draft 09-27-13, section 20.2.2.28. 171 // ES6 draft 09-27-13, section 20.2.2.28.
172 function MathSign(x) { 172 function MathSign(x) {
173 x = TO_NUMBER_INLINE(x); 173 x = TO_NUMBER_INLINE(x);
174 if (x > 0) return 1; 174 if (x > 0) return 1;
175 if (x < 0) return -1; 175 if (x < 0) return -1;
176 if (x === 0) return x; 176 // -0, 0 or NaN.
177 return NAN; 177 return x;
178 } 178 }
179 179
180 // ES6 draft 09-27-13, section 20.2.2.34. 180 // ES6 draft 09-27-13, section 20.2.2.34.
181 function MathTrunc(x) { 181 function MathTrunc(x) {
182 x = TO_NUMBER_INLINE(x); 182 x = TO_NUMBER_INLINE(x);
183 if (x > 0) return MathFloor(x); 183 if (x > 0) return MathFloor(x);
184 if (x < 0) return MathCeil(x); 184 if (x < 0) return MathCeil(x);
185 if (x === 0) return x; 185 // -0, 0 or NaN.
186 return NAN; 186 return x;
187 } 187 }
188 188
189 // ES6 draft 09-27-13, section 20.2.2.30. 189 // ES6 draft 09-27-13, section 20.2.2.30.
190 function MathSinh(x) { 190 function MathSinh(x) {
191 if (!IS_NUMBER(x)) x = NonNumberToNumber(x); 191 if (!IS_NUMBER(x)) x = NonNumberToNumber(x);
192 // Idempotent for NaN, +/-0 and +/-Infinity. 192 // Idempotent for NaN, +/-0 and +/-Infinity.
193 if (x === 0 || !NUMBER_IS_FINITE(x)) return x; 193 if (x === 0 || !NUMBER_IS_FINITE(x)) return x;
194 return (MathExp(x) - MathExp(-x)) / 2; 194 return (MathExp(x) - MathExp(-x)) / 2;
195 } 195 }
196 196
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 "expm1", MathExpm1 // implemented by third_party/fdlibm 392 "expm1", MathExpm1 // implemented by third_party/fdlibm
393 )); 393 ));
394 394
395 %SetInlineBuiltinFlag(MathCeil); 395 %SetInlineBuiltinFlag(MathCeil);
396 %SetInlineBuiltinFlag(MathRandom); 396 %SetInlineBuiltinFlag(MathRandom);
397 %SetInlineBuiltinFlag(MathSin); 397 %SetInlineBuiltinFlag(MathSin);
398 %SetInlineBuiltinFlag(MathCos); 398 %SetInlineBuiltinFlag(MathCos);
399 } 399 }
400 400
401 SetUpMath(); 401 SetUpMath();
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698