Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1044)

Unified Diff: src/utils.h

Issue 1234073003: V8: Add utility functions to check SameValue and SameValueZero. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Adam's comments. Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/objects.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/utils.h
diff --git a/src/utils.h b/src/utils.h
index 582c5769936947698217cf5fd5ef219ab7e919eb..eeea4da21623acf917c94e510633a4d47c75d4ac 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -200,6 +200,27 @@ inline double Floor(double x) {
return std::floor(x);
}
+// Implements the ES5 SameValue operation for floating point types.
+// http://www.ecma-international.org/ecma-262/6.0/#sec-samevalue
+template <typename T>
+bool SameValue(T x, T y) {
+ // 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;
+}
+
+
+// Implements the ES6 SameValueZero operation for floating point types.
+// http://www.ecma-international.org/ecma-262/6.0/#sec-samevaluezero
+template <typename T>
+bool SameValueZero(T x, T y) {
+ 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) {
« no previous file with comments | « src/objects.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698