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

Unified Diff: src/harmony-math.js

Issue 28793002: Harmony: implement Math.trunc. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: inline number conversion Created 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/math.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/harmony-math.js
diff --git a/src/harmony-math.js b/src/harmony-math.js
index 2e9b42a75e7cf368af023c29baaf9cd24663a3b8..a4d3f2e8a5e9c5936630571644605402dee1199d 100644
--- a/src/harmony-math.js
+++ b/src/harmony-math.js
@@ -29,7 +29,7 @@
// ES6 draft 09-27-13, section 20.2.2.28.
function MathSign(x) {
- if (!IS_NUMBER(x)) x = NonNumberToNumber(x);
+ x = TO_NUMBER_INLINE(x);
if (x > 0) return 1;
if (x < 0) return -1;
if (x === 0) return x;
@@ -37,12 +37,23 @@ function MathSign(x) {
}
+// ES6 draft 09-27-13, section 20.2.2.34.
+function MathTrunc(x) {
+ x = TO_NUMBER_INLINE(x);
+ if (x > 0) return MathFloor(x);
+ if (x < 0) return MathCeil(x);
+ if (x === 0) return x;
+ return NAN;
+}
+
+
function ExtendMath() {
%CheckIsBootstrapping();
// Set up the non-enumerable functions on the Math object.
InstallFunctions($Math, DONT_ENUM, $Array(
- "sign", MathSign
+ "sign", MathSign,
+ "trunc", MathTrunc
));
}
« no previous file with comments | « no previous file | src/math.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698