Commit 6a2e0cd2 authored by yangguo@chromium.org's avatar yangguo@chromium.org

Check for negative zero in floor when compiling with MSVC.

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
parent c6cf7e54
...@@ -4172,11 +4172,11 @@ HInstruction* HUnaryMathOperation::New( ...@@ -4172,11 +4172,11 @@ HInstruction* HUnaryMathOperation::New(
// Doubles are represented as Significant * 2 ^ Exponent. If the // Doubles are represented as Significant * 2 ^ Exponent. If the
// Exponent is not negative, the double value is already an integer. // Exponent is not negative, the double value is already an integer.
if (Double(d).Exponent() >= 0) return H_CONSTANT_DOUBLE(d); 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: case kMathFround:
return H_CONSTANT_DOUBLE(static_cast<double>(static_cast<float>(d))); return H_CONSTANT_DOUBLE(static_cast<double>(static_cast<float>(d)));
case kMathFloor: case kMathFloor:
return H_CONSTANT_DOUBLE(std::floor(d)); return H_CONSTANT_DOUBLE(Floor(d));
case kMathClz32: { case kMathClz32: {
uint32_t i = DoubleToUint32(d); uint32_t i = DoubleToUint32(d);
return H_CONSTANT_INT( return H_CONSTANT_INT(
......
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
#include "src/string-search.h" #include "src/string-search.h"
#include "src/stub-cache.h" #include "src/stub-cache.h"
#include "src/uri.h" #include "src/uri.h"
#include "src/utils.h"
#include "src/v8threads.h" #include "src/v8threads.h"
#include "src/vm-state-inl.h" #include "src/vm-state-inl.h"
...@@ -7712,7 +7713,7 @@ RUNTIME_FUNCTION(Runtime_MathFloorRT) { ...@@ -7712,7 +7713,7 @@ RUNTIME_FUNCTION(Runtime_MathFloorRT) {
isolate->counters()->math_floor()->Increment(); isolate->counters()->math_floor()->Increment();
CONVERT_DOUBLE_ARG_CHECKED(x, 0); 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) { ...@@ -7797,7 +7798,7 @@ RUNTIME_FUNCTION(Runtime_RoundNumber) {
if (sign && value >= -0.5) return isolate->heap()->minus_zero_value(); if (sign && value >= -0.5) return isolate->heap()->minus_zero_value();
// Do not call NumberFromDouble() to avoid extra checks. // 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) { ...@@ -9522,9 +9523,9 @@ RUNTIME_FUNCTION(Runtime_DateCurrentTime) {
double millis; double millis;
if (FLAG_verify_predictable) { if (FLAG_verify_predictable) {
millis = 1388534400000.0; // Jan 1 2014 00:00:00 GMT+0000 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 { } else {
millis = std::floor(base::OS::TimeCurrentMillis()); millis = Floor(base::OS::TimeCurrentMillis());
} }
return *isolate->factory()->NewNumber(millis); return *isolate->factory()->NewNumber(millis);
} }
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <limits.h> #include <limits.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <cmath>
#include "include/v8.h" #include "include/v8.h"
#include "src/allocation.h" #include "src/allocation.h"
...@@ -140,6 +141,15 @@ T Abs(T a) { ...@@ -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. // TODO(svenpanne) Clean up the whole power-of-2 mess.
inline int32_t WhichPowerOf2Abs(int32_t x) { inline int32_t WhichPowerOf2Abs(int32_t x) {
return (x == kMinInt) ? 31 : WhichPowerOf2(Abs(x)); return (x == kMinInt) ? 31 : WhichPowerOf2(Abs(x));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment