Revision: 22674
Author:   [email protected]
Date:     Tue Jul 29 14:20:05 2014 UTC
Log:      Check for negative zero in floor when compiling with MSVC.

[email protected]
BUG=v8:3477
LOG=N

Review URL: https://codereview.chromium.org/429603003
http://code.google.com/p/v8/source/detail?r=22674

Modified:
 /branches/bleeding_edge/src/hydrogen-instructions.cc
 /branches/bleeding_edge/src/runtime.cc
 /branches/bleeding_edge/src/utils.h

=======================================
--- /branches/bleeding_edge/src/hydrogen-instructions.cc Tue Jul 29 11:34:08 2014 UTC +++ /branches/bleeding_edge/src/hydrogen-instructions.cc Tue Jul 29 14:20:05 2014 UTC
@@ -4172,11 +4172,11 @@
         // Doubles are represented as Significant * 2 ^ Exponent. If the
// Exponent is not negative, the double value is already an integer.
         if (Double(d).Exponent() >= 0) return H_CONSTANT_DOUBLE(d);
-        return H_CONSTANT_DOUBLE(std::floor(d + 0.5));
+        return H_CONSTANT_DOUBLE(Floor(d + 0.5));
       case kMathFround:
return H_CONSTANT_DOUBLE(static_cast<double>(static_cast<float>(d)));
       case kMathFloor:
-        return H_CONSTANT_DOUBLE(std::floor(d));
+        return H_CONSTANT_DOUBLE(Floor(d));
       case kMathClz32: {
         uint32_t i = DoubleToUint32(d);
         return H_CONSTANT_INT(
=======================================
--- /branches/bleeding_edge/src/runtime.cc      Tue Jul 29 08:09:14 2014 UTC
+++ /branches/bleeding_edge/src/runtime.cc      Tue Jul 29 14:20:05 2014 UTC
@@ -42,6 +42,7 @@
 #include "src/string-search.h"
 #include "src/stub-cache.h"
 #include "src/uri.h"
+#include "src/utils.h"
 #include "src/v8threads.h"
 #include "src/vm-state-inl.h"

@@ -7712,7 +7713,7 @@
   isolate->counters()->math_floor()->Increment();

   CONVERT_DOUBLE_ARG_CHECKED(x, 0);
-  return *isolate->factory()->NewNumber(std::floor(x));
+  return *isolate->factory()->NewNumber(Floor(x));
 }


@@ -7797,7 +7798,7 @@
   if (sign && value >= -0.5) return isolate->heap()->minus_zero_value();

   // Do not call NumberFromDouble() to avoid extra checks.
-  return *isolate->factory()->NewNumber(std::floor(value + 0.5));
+  return *isolate->factory()->NewNumber(Floor(value + 0.5));
 }


@@ -9522,9 +9523,9 @@
   double millis;
   if (FLAG_verify_predictable) {
     millis = 1388534400000.0;  // Jan 1 2014 00:00:00 GMT+0000
-    millis += std::floor(isolate->heap()->synthetic_time());
+    millis += Floor(isolate->heap()->synthetic_time());
   } else {
-    millis = std::floor(base::OS::TimeCurrentMillis());
+    millis = Floor(base::OS::TimeCurrentMillis());
   }
   return *isolate->factory()->NewNumber(millis);
 }
=======================================
--- /branches/bleeding_edge/src/utils.h Fri Jul 11 12:12:58 2014 UTC
+++ /branches/bleeding_edge/src/utils.h Tue Jul 29 14:20:05 2014 UTC
@@ -8,6 +8,7 @@
 #include <limits.h>
 #include <stdlib.h>
 #include <string.h>
+#include <cmath>

 #include "include/v8.h"
 #include "src/allocation.h"
@@ -138,6 +139,15 @@
 T Abs(T a) {
   return a < 0 ? -a : a;
 }
+
+
+// Floor(-0.0) == 0.0
+inline double Floor(double x) {
+#ifdef _MSC_VER
+  if (x == 0) return x;  // Fix for issue 3477.
+#endif
+  return std::floor(x);
+}


 // TODO(svenpanne) Clean up the whole power-of-2 mess.

--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to