Reviewers: danno,
Description:
Check for negative zero in floor when compiling with MSVC.
[email protected]
BUG=v8:3477
LOG=N
Please review this at https://codereview.chromium.org/429603003/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files (+17, -6 lines):
M src/hydrogen-instructions.cc
M src/runtime.cc
M src/utils.h
Index: src/hydrogen-instructions.cc
diff --git a/src/hydrogen-instructions.cc b/src/hydrogen-instructions.cc
index
1e85ada0b811e976206eea779ad8498f99fa55d9..a0d02b5d05aff1d02ea08f4eb4b4fce086cf6c6d
100644
--- a/src/hydrogen-instructions.cc
+++ b/src/hydrogen-instructions.cc
@@ -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: src/runtime.cc
diff --git a/src/runtime.cc b/src/runtime.cc
index
ba6f33c5313ed589930c4808fb00553383aeca3b..518e96a99bfc0c1cf6f636793a5784d5e0373a5a
100644
--- a/src/runtime.cc
+++ b/src/runtime.cc
@@ -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: src/utils.h
diff --git a/src/utils.h b/src/utils.h
index
7831fa9fee6e14778f467c74498784b0c2f57e7b..d7967e7f0e20a49c4768ce9cedff3c5e9ad65581
100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -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));
--
--
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.