Bug 747197 - abs works on ints, fabs works on doubles, grasshopper. Smallest bugfix ever. r=terrence
authorJeff Walden <jwalden@mit.edu>
Thu, 26 Apr 2012 17:19:04 -0700
changeset 92565 ef7803bad0b1f468850b50f3c4c009c848d3db6b
parent 92564 e8bf76219f364346ef1b0e0b93636e819e1c9935
child 92566 9bab3e0dd69d7c6628fb7f8983a5e4acb6566980
push id8754
push userjwalden@mit.edu
push dateFri, 27 Apr 2012 01:06:57 +0000
treeherdermozilla-inbound@b7a03f6f1a3e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersterrence
bugs747197
milestone15.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 747197 - abs works on ints, fabs works on doubles, grasshopper. Smallest bugfix ever. r=terrence
js/src/jsdate.h
js/src/tests/ecma_5/Date/timeclip.js
--- a/js/src/jsdate.h
+++ b/js/src/jsdate.h
@@ -59,17 +59,17 @@ struct JSContext;
 
 namespace js {
 
 /* ES5 15.9.1.14. */
 inline double
 TimeClip(double time)
 {
     /* Steps 1-2. */
-    if (!MOZ_DOUBLE_IS_FINITE(time) || abs(time) > 8.64e15)
+    if (!MOZ_DOUBLE_IS_FINITE(time) || fabs(time) > 8.64e15)
         return js_NaN;
 
     /* Step 3. */
     return ToInteger(time + (+0.0));
 }
 
 } /* namespace js */
 
new file mode 100644
--- /dev/null
+++ b/js/src/tests/ecma_5/Date/timeclip.js
@@ -0,0 +1,42 @@
+/*
+ * Any copyright is dedicated to the Public Domain.
+ * http://creativecommonn.org/licenses/publicdomain/
+ */
+
+var BUGNUMBER = 747197;
+var summary = "TimeClip behavior for very large numbers";
+
+print(BUGNUMBER + ": " + summary);
+
+/**************
+ * BEGIN TEST *
+ **************/
+
+function addToLimit(n) { return 8.64e15 + n; }
+
+assertEq(8.64e15 === addToLimit(0.0), true);
+assertEq(8.64e15 === addToLimit(0.5), true);
+assertEq(8.64e15 === addToLimit(0.5000000000000001), false);
+
+var times =
+  [Number.MAX_VALUE,
+   -Number.MAX_VALUE,
+   Infinity,
+   -Infinity,
+   addToLimit(0.5000000000000001),
+   -addToLimit(0.5000000000000001)];
+
+for (var i = 0, len = times.length; i < len; i++)
+{
+  var d = new Date();
+  assertEq(d.setTime(times[i]), NaN, "times[" + i + "]");
+  assertEq(d.getTime(), NaN);
+  assertEq(d.valueOf(), NaN);
+}
+
+/******************************************************************************/
+
+if (typeof reportCompare === "function")
+  reportCompare(true, true);
+
+print("Tests complete");