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

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: Clean up. 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
« src/objects.cc ('K') | « 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..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));
« src/objects.cc ('K') | « src/objects.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698