summaryrefslogtreecommitdiff
path: root/core/fxcrt/fx_extension.h
diff options
context:
space:
mode:
Diffstat (limited to 'core/fxcrt/fx_extension.h')
-rw-r--r--core/fxcrt/fx_extension.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/core/fxcrt/fx_extension.h b/core/fxcrt/fx_extension.h
index cef943fc99..dcdd64e1fc 100644
--- a/core/fxcrt/fx_extension.h
+++ b/core/fxcrt/fx_extension.h
@@ -8,6 +8,7 @@
#define CORE_FXCRT_FX_EXTENSION_H_
#include <cctype>
+#include <cmath>
#include <cwctype>
#include <memory>
@@ -92,4 +93,20 @@ void FXSYS_IntToFourHexChars(uint16_t c, char* buf);
size_t FXSYS_ToUTF16BE(uint32_t unicode, char* buf);
+// Strict order over floating types where NaNs may be present.
+template <typename T>
+bool FXSYS_SafeEQ(const T& lhs, const T& rhs) {
+ return (std::isnan(lhs) && std::isnan(rhs)) ||
+ (!std::isnan(lhs) && !std::isnan(rhs) && lhs == rhs);
+}
+
+template <typename T>
+bool FXSYS_SafeLT(const T& lhs, const T& rhs) {
+ if (std::isnan(lhs) && std::isnan(rhs))
+ return false;
+ if (std::isnan(lhs) || std::isnan(rhs))
+ return std::isnan(lhs) < std::isnan(rhs);
+ return lhs < rhs;
+}
+
#endif // CORE_FXCRT_FX_EXTENSION_H_