Issue #2241 - Part 2: Add SameValueZero implementation to mfbt/FloatingPoint.h

Backported from Mozilla bug 1560658.

This is to prevent duplication of code while implementing DOMMatrix operations.
This commit is contained in:
Job Bautista 2023-05-10 19:22:39 +08:00 • committed by roytam1
commit 621868a340
2 changed files with 27 additions and 0 deletions

View file

@ -8,6 +8,8 @@
#ifndef js_Equality_h
#define js_Equality_h
#include "mozilla/FloatingPoint.h"
#include "jstypes.h" // JS_PUBLIC_API
#include "js/RootingAPI.h" // JS::Handle
@ -50,6 +52,17 @@ LooselyEqual(JSContext* cx, JS::Handle<JS::Value> v1, JS::Handle<JS::Value> v2,
extern JS_PUBLIC_API(bool)
SameValue(JSContext* cx, JS::Handle<JS::Value> v1, JS::Handle<JS::Value> v2, bool* same);
/**
* Implements |SameValueZero(v1, v2)| for Number values |v1| and |v2|.
* SameValueZero equates NaNs, equal nonzero values, and zeroes without respect
* to their signs.
*/
static inline bool
SameValueZero(double v1, double v2)
{
return mozilla::EqualOrBothNaN(v1, v2);
}
} // namespace JS
#endif /* js_Equality_h */