Check for negative zero in floor when compiling with MSVC.
authoryangguo@chromium.org <yangguo@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Tue, 29 Jul 2014 14:20:05 +0000 (14:20 +0000)
committeryangguo@chromium.org <yangguo@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Tue, 29 Jul 2014 14:20:05 +0000 (14:20 +0000)
R=danno@chromium.org
BUG=v8:3477
LOG=N

Review URL: https://codereview.chromium.org/429603003

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@22674 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

src/hydrogen-instructions.cc
src/runtime.cc
src/utils.h

index 1e85ada0b811e976206eea779ad8498f99fa55d9..a0d02b5d05aff1d02ea08f4eb4b4fce086cf6c6d 100644 (file)
@@ -4172,11 +4172,11 @@ HInstruction* HUnaryMathOperation::New(
         // 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(
index ba6f33c5313ed589930c4808fb00553383aeca3b..518e96a99bfc0c1cf6f636793a5784d5e0373a5a 100644 (file)
@@ -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 @@ RUNTIME_FUNCTION(Runtime_MathFloorRT) {
   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 @@ RUNTIME_FUNCTION(Runtime_RoundNumber) {
   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 @@ RUNTIME_FUNCTION(Runtime_DateCurrentTime) {
   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);
 }
index 7831fa9fee6e14778f467c74498784b0c2f57e7b..d7967e7f0e20a49c4768ce9cedff3c5e9ad65581 100644 (file)
@@ -8,6 +8,7 @@
 #include <limits.h>
 #include <stdlib.h>
 #include <string.h>
+#include <cmath>
 
 #include "include/v8.h"
 #include "src/allocation.h"
@@ -140,6 +141,15 @@ T Abs(T 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.
 inline int32_t WhichPowerOf2Abs(int32_t x) {
   return (x == kMinInt) ? 31 : WhichPowerOf2(Abs(x));