aboutsummaryrefslogtreecommitdiff
path: root/node_modules/es5-ext/math/trunc
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/es5-ext/math/trunc')
-rw-r--r--node_modules/es5-ext/math/trunc/implement.js8
-rw-r--r--node_modules/es5-ext/math/trunc/index.js5
-rw-r--r--node_modules/es5-ext/math/trunc/is-implemented.js7
-rw-r--r--node_modules/es5-ext/math/trunc/shim.js13
4 files changed, 33 insertions, 0 deletions
diff --git a/node_modules/es5-ext/math/trunc/implement.js b/node_modules/es5-ext/math/trunc/implement.js
new file mode 100644
index 000000000..1ecc124cd
--- /dev/null
+++ b/node_modules/es5-ext/math/trunc/implement.js
@@ -0,0 +1,8 @@
+"use strict";
+
+if (!require("./is-implemented")()) {
+ Object.defineProperty(Math, "trunc", { value: require("./shim"),
+ configurable: true,
+enumerable: false,
+writable: true });
+}
diff --git a/node_modules/es5-ext/math/trunc/index.js b/node_modules/es5-ext/math/trunc/index.js
new file mode 100644
index 000000000..94c02691a
--- /dev/null
+++ b/node_modules/es5-ext/math/trunc/index.js
@@ -0,0 +1,5 @@
+"use strict";
+
+module.exports = require("./is-implemented")()
+ ? Math.trunc
+ : require("./shim");
diff --git a/node_modules/es5-ext/math/trunc/is-implemented.js b/node_modules/es5-ext/math/trunc/is-implemented.js
new file mode 100644
index 000000000..b1507352e
--- /dev/null
+++ b/node_modules/es5-ext/math/trunc/is-implemented.js
@@ -0,0 +1,7 @@
+"use strict";
+
+module.exports = function () {
+ var trunc = Math.trunc;
+ if (typeof trunc !== "function") return false;
+ return (trunc(13.67) === 13) && (trunc(-13.67) === -13);
+};
diff --git a/node_modules/es5-ext/math/trunc/shim.js b/node_modules/es5-ext/math/trunc/shim.js
new file mode 100644
index 000000000..bf6ac8cce
--- /dev/null
+++ b/node_modules/es5-ext/math/trunc/shim.js
@@ -0,0 +1,13 @@
+"use strict";
+
+var floor = Math.floor;
+
+module.exports = function (value) {
+ if (isNaN(value)) return NaN;
+ value = Number(value);
+ if (value === 0) return value;
+ if (value === Infinity) return Infinity;
+ if (value === -Infinity) return -Infinity;
+ if (value > 0) return floor(value);
+ return -floor(-value);
+};