From 189ceb67037e7dc5e9b19ba0ba3b94d9e4d2c60a Mon Sep 17 00:00:00 2001 From: David Neto Date: Fri, 20 Nov 2020 19:34:34 +0000 Subject: [PATCH] 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 Commit-Queue: Ben Clayton Auto-Submit: David Neto Reviewed-by: Ben Clayton --- src/writer/float_to_string_test.cc | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/writer/float_to_string_test.cc b/src/writer/float_to_string_test.cc index ca1a066c7f..dda45544bd 100644 --- a/src/writer/float_to_string_test.cc +++ b/src/writer/float_to_string_test.cc @@ -43,8 +43,9 @@ TEST(FloatToStringTest, Small) { } TEST(FloatToStringTest, Highest) { - if (std::numeric_limits::max() != - 340282346638528859811704183484516925440.0f) { + const auto highest = std::numeric_limits::max(); + const auto expected_highest = 340282346638528859811704183484516925440.0f; + if (highest < expected_highest || highest > expected_highest) { GTEST_SKIP() << "std::numeric_limits::max() is not as expected for " "this target"; } @@ -53,8 +54,11 @@ TEST(FloatToStringTest, Highest) { } TEST(FloatToStringTest, Lowest) { - if (std::numeric_limits::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::lowest(); + const auto expected_lowest = -340282346638528859811704183484516925440.0f; + if (lowest < expected_lowest || lowest > expected_lowest) { GTEST_SKIP() << "std::numeric_limits::lowest() is not as expected for " "this target";