From fc2d681e2a3b76edcc588dd4b5b3ae877e0fb3fa Mon Sep 17 00:00:00 2001 From: OverMighty Date: Wed, 24 Jul 2024 15:58:18 +0200 Subject: [PATCH] [libc][math][c23] Fix totalorder and totalordermag smoke tests (#100354) Summary: FPBits::signaling_nan() defaults to setting the MSB of the payload to 1. The tests also used signaling NaNs with a payload of 0x123. With float16, the 1 in 0x123 aligns to the MSB of the payload, therefore 0x123 is greater than the default payload. However, that is not the case with more precise floating-point types. Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: https://phabricator.intern.facebook.com/D60250676 --- libc/test/src/math/smoke/TotalOrderMagTest.h | 24 ++++++++++---------- libc/test/src/math/smoke/TotalOrderTest.h | 24 ++++++++++---------- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/libc/test/src/math/smoke/TotalOrderMagTest.h b/libc/test/src/math/smoke/TotalOrderMagTest.h index 5fe2983a0e678b..3d7f24fc74d10e 100644 --- a/libc/test/src/math/smoke/TotalOrderMagTest.h +++ b/libc/test/src/math/smoke/TotalOrderMagTest.h @@ -104,24 +104,24 @@ class TotalOrderMagTestTemplate : public LIBC_NAMESPACE::testing::FEnvSafeTest { } void testNaNPayloads(TotalOrderMagFunc func) { - T qnan_123 = FPBits::quiet_nan(Sign::POS, 0x123).get_val(); - T neg_qnan_123 = FPBits::quiet_nan(Sign::NEG, 0x123).get_val(); - T snan_123 = FPBits::signaling_nan(Sign::POS, 0x123).get_val(); - T neg_snan_123 = FPBits::signaling_nan(Sign::NEG, 0x123).get_val(); + T qnan_0x42 = FPBits::quiet_nan(Sign::POS, 0x42).get_val(); + T neg_qnan_0x42 = FPBits::quiet_nan(Sign::NEG, 0x42).get_val(); + T snan_0x42 = FPBits::signaling_nan(Sign::POS, 0x42).get_val(); + T neg_snan_0x42 = FPBits::signaling_nan(Sign::NEG, 0x42).get_val(); EXPECT_TRUE(funcWrapper(func, aNaN, aNaN)); EXPECT_TRUE(funcWrapper(func, sNaN, sNaN)); - EXPECT_TRUE(funcWrapper(func, aNaN, qnan_123)); - EXPECT_TRUE(funcWrapper(func, sNaN, snan_123)); - EXPECT_FALSE(funcWrapper(func, qnan_123, aNaN)); - EXPECT_FALSE(funcWrapper(func, snan_123, sNaN)); + EXPECT_TRUE(funcWrapper(func, aNaN, qnan_0x42)); + EXPECT_FALSE(funcWrapper(func, sNaN, snan_0x42)); + EXPECT_FALSE(funcWrapper(func, qnan_0x42, aNaN)); + EXPECT_TRUE(funcWrapper(func, snan_0x42, sNaN)); EXPECT_TRUE(funcWrapper(func, neg_aNaN, neg_aNaN)); EXPECT_TRUE(funcWrapper(func, neg_sNaN, neg_sNaN)); - EXPECT_TRUE(funcWrapper(func, neg_aNaN, neg_qnan_123)); - EXPECT_TRUE(funcWrapper(func, neg_sNaN, neg_snan_123)); - EXPECT_FALSE(funcWrapper(func, neg_qnan_123, neg_aNaN)); - EXPECT_FALSE(funcWrapper(func, neg_snan_123, neg_sNaN)); + EXPECT_TRUE(funcWrapper(func, neg_aNaN, neg_qnan_0x42)); + EXPECT_FALSE(funcWrapper(func, neg_sNaN, neg_snan_0x42)); + EXPECT_FALSE(funcWrapper(func, neg_qnan_0x42, neg_aNaN)); + EXPECT_TRUE(funcWrapper(func, neg_snan_0x42, neg_sNaN)); } }; diff --git a/libc/test/src/math/smoke/TotalOrderTest.h b/libc/test/src/math/smoke/TotalOrderTest.h index 281b2a59f930db..4d4257d089daf7 100644 --- a/libc/test/src/math/smoke/TotalOrderTest.h +++ b/libc/test/src/math/smoke/TotalOrderTest.h @@ -102,24 +102,24 @@ class TotalOrderTestTemplate : public LIBC_NAMESPACE::testing::FEnvSafeTest { } void testNaNPayloads(TotalOrderFunc func) { - T qnan_123 = FPBits::quiet_nan(Sign::POS, 0x123).get_val(); - T neg_qnan_123 = FPBits::quiet_nan(Sign::NEG, 0x123).get_val(); - T snan_123 = FPBits::signaling_nan(Sign::POS, 0x123).get_val(); - T neg_snan_123 = FPBits::signaling_nan(Sign::NEG, 0x123).get_val(); + T qnan_0x42 = FPBits::quiet_nan(Sign::POS, 0x42).get_val(); + T neg_qnan_0x42 = FPBits::quiet_nan(Sign::NEG, 0x42).get_val(); + T snan_0x42 = FPBits::signaling_nan(Sign::POS, 0x42).get_val(); + T neg_snan_0x42 = FPBits::signaling_nan(Sign::NEG, 0x42).get_val(); EXPECT_TRUE(funcWrapper(func, aNaN, aNaN)); EXPECT_TRUE(funcWrapper(func, sNaN, sNaN)); - EXPECT_TRUE(funcWrapper(func, aNaN, qnan_123)); - EXPECT_TRUE(funcWrapper(func, sNaN, snan_123)); - EXPECT_FALSE(funcWrapper(func, qnan_123, aNaN)); - EXPECT_FALSE(funcWrapper(func, snan_123, sNaN)); + EXPECT_TRUE(funcWrapper(func, aNaN, qnan_0x42)); + EXPECT_FALSE(funcWrapper(func, sNaN, snan_0x42)); + EXPECT_FALSE(funcWrapper(func, qnan_0x42, aNaN)); + EXPECT_TRUE(funcWrapper(func, snan_0x42, sNaN)); EXPECT_TRUE(funcWrapper(func, neg_aNaN, neg_aNaN)); EXPECT_TRUE(funcWrapper(func, neg_sNaN, neg_sNaN)); - EXPECT_FALSE(funcWrapper(func, neg_aNaN, neg_qnan_123)); - EXPECT_FALSE(funcWrapper(func, neg_sNaN, neg_snan_123)); - EXPECT_TRUE(funcWrapper(func, neg_qnan_123, neg_aNaN)); - EXPECT_TRUE(funcWrapper(func, neg_snan_123, neg_sNaN)); + EXPECT_FALSE(funcWrapper(func, neg_aNaN, neg_qnan_0x42)); + EXPECT_TRUE(funcWrapper(func, neg_sNaN, neg_snan_0x42)); + EXPECT_TRUE(funcWrapper(func, neg_qnan_0x42, neg_aNaN)); + EXPECT_FALSE(funcWrapper(func, neg_snan_0x42, neg_sNaN)); } };