Avoid floating point equality checks in tests
Make newer Apple clangs happy even with -Wfloat-equal
Change-Id: I186c03811b3ed582f740afd3f01ea09090e6b7e1
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/33600
Commit-Queue: David Neto <dneto@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Auto-Submit: David Neto <dneto@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
diff --git a/src/writer/float_to_string_test.cc b/src/writer/float_to_string_test.cc
index ca1a066..dda4554 100644
--- a/src/writer/float_to_string_test.cc
+++ b/src/writer/float_to_string_test.cc
@@ -43,8 +43,9 @@
}
TEST(FloatToStringTest, Highest) {
- if (std::numeric_limits<float>::max() !=
- 340282346638528859811704183484516925440.0f) {
+ const auto highest = std::numeric_limits<float>::max();
+ const auto expected_highest = 340282346638528859811704183484516925440.0f;
+ if (highest < expected_highest || highest > expected_highest) {
GTEST_SKIP() << "std::numeric_limits<float>::max() is not as expected for "
"this target";
}
@@ -53,8 +54,11 @@
}
TEST(FloatToStringTest, Lowest) {
- if (std::numeric_limits<float>::lowest() !=
- -340282346638528859811704183484516925440.0f) {
+ // Some compilers complain if you test floating point numbers for equality.
+ // So say it via two inequalities.
+ const auto lowest = std::numeric_limits<float>::lowest();
+ const auto expected_lowest = -340282346638528859811704183484516925440.0f;
+ if (lowest < expected_lowest || lowest > expected_lowest) {
GTEST_SKIP()
<< "std::numeric_limits<float>::lowest() is not as expected for "
"this target";