Index: src/utils.h |
diff --git a/src/utils.h b/src/utils.h |
index 582c5769936947698217cf5fd5ef219ab7e919eb..1cbcdf4aafb6677eac00ad5911f95bc149aaa129 100644 |
--- a/src/utils.h |
+++ b/src/utils.h |
@@ -201,6 +201,24 @@ inline double Floor(double x) { |
} |
+template <typename T> |
+bool SameValue(T x, T y) { |
adamk
2015/07/14 18:26:58
Can you add a comment linking to:
http://www.ecma
bbudge
2015/07/14 20:26:24
Done.
|
+ // SameValue(NaN, NaN) is true. |
+ if (x != y) return std::isnan(x) && std::isnan(y); |
+ // SameValue(0, -0) is false. |
+ if (std::signbit(x) != std::signbit(y)) return false; |
+ return true; |
+} |
+ |
+ |
+template <typename T> |
+bool SameValueZero(T x, T y) { |
adamk
2015/07/14 18:26:58
And here linking to:
http://www.ecma-internationa
bbudge
2015/07/14 20:26:24
Done.
|
+ if (x != y) return std::isnan(x) && std::isnan(y); |
+ // SameValueZero doesn't distinguish between 0 and -0. |
+ return true; |
+} |
+ |
+ |
// TODO(svenpanne) Clean up the whole power-of-2 mess. |
inline int32_t WhichPowerOf2Abs(int32_t x) { |
return (x == kMinInt) ? 31 : WhichPowerOf2(Abs(x)); |