142 changes: 137 additions & 5 deletions libc/test/src/__support/FPUtil/fpbits_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,22 @@

#include "src/__support/FPUtil/FPBits.h"
#include "src/__support/FPUtil/fpbits_str.h"
#include "src/__support/big_int.h"
#include "src/__support/integer_literals.h"
#include "src/__support/macros/properties/types.h"
#include "src/__support/sign.h" // Sign
#include "test/UnitTest/Test.h"

using LIBC_NAMESPACE::Sign;
using LIBC_NAMESPACE::UInt;
using LIBC_NAMESPACE::fputil::FPBits;
using LIBC_NAMESPACE::fputil::FPType;
using LIBC_NAMESPACE::fputil::internal::FPRep;

using LIBC_NAMESPACE::operator""_u16;
using LIBC_NAMESPACE::operator""_u32;
using LIBC_NAMESPACE::operator""_u64;
using LIBC_NAMESPACE::operator""_u96;
using LIBC_NAMESPACE::operator""_u128;

TEST(LlvmLibcFPBitsTest, FPType_IEEE754_Binary16) {
Expand Down Expand Up @@ -124,6 +127,7 @@ TEST(LlvmLibcFPBitsTest, FPType_IEEE754_Binary128) {
TEST(LlvmLibcFPBitsTest, FPType_X86_Binary80) {
using Rep = FPRep<FPType::X86_Binary80>;

#if __SIZEOF_LONG_DOUBLE__ == 16
EXPECT_EQ(
0b0'0000000000000000000000000000000000000000000000000000000000000000000000000000000_u128,
UInt128(Rep::zero()));
Expand Down Expand Up @@ -151,11 +155,43 @@ TEST(LlvmLibcFPBitsTest, FPType_X86_Binary80) {
EXPECT_EQ(
0b0'1111111111111111100000000000000000000000000000000000000000000000000000000000000_u128,
UInt128(Rep::quiet_nan()));
#elif __SIZEOF_LONG_DOUBLE__ == 12
EXPECT_EQ(
0b0'0000000000000000000000000000000000000000000000000000000000000000000000000000000_u96,
UInt<96>(Rep::zero()));
EXPECT_EQ(
0b0'0111111111111111000000000000000000000000000000000000000000000000000000000000000_u96,
UInt<96>(Rep::one()));
EXPECT_EQ(
0b0'0000000000000000000000000000000000000000000000000000000000000000000000000000001_u96,
UInt<96>(Rep::min_subnormal()));
EXPECT_EQ(
0b0'0000000000000000111111111111111111111111111111111111111111111111111111111111111_u96,
UInt<96>(Rep::max_subnormal()));
EXPECT_EQ(
0b0'0000000000000011000000000000000000000000000000000000000000000000000000000000000_u96,
UInt<96>(Rep::min_normal()));
EXPECT_EQ(
0b0'1111111111111101111111111111111111111111111111111111111111111111111111111111111_u96,
UInt<96>(Rep::max_normal()));
EXPECT_EQ(
0b0'1111111111111111000000000000000000000000000000000000000000000000000000000000000_u96,
UInt<96>(Rep::inf()));
EXPECT_EQ(
0b0'1111111111111111010000000000000000000000000000000000000000000000000000000000000_u96,
UInt<96>(Rep::signaling_nan()));
EXPECT_EQ(
0b0'1111111111111111100000000000000000000000000000000000000000000000000000000000000_u96,
UInt<96>(Rep::quiet_nan()));
#else
#error "unhandled long double type"
#endif
}

TEST(LlvmLibcFPBitsTest, FPType_X86_Binary80_IsNan) {
using Rep = FPRep<FPType::X86_Binary80>;

#if __SIZEOF_LONG_DOUBLE__ == 16
EXPECT_TRUE( // NAN : Pseudo-Infinity
Rep(0b0'111111111111111'0000000000000000000000000000000000000000000000000000000000000000_u128)
.is_nan());
Expand Down Expand Up @@ -192,6 +228,46 @@ TEST(LlvmLibcFPBitsTest, FPType_X86_Binary80_IsNan) {
EXPECT_FALSE( // Normalized
Rep(0b0'111111111111110'1000000000000000000000000000000000000000000000000000000000000000_u128)
.is_nan());
#elif __SIZEOF_LONG_DOUBLE__ == 12
EXPECT_TRUE( // NAN : Pseudo-Infinity
Rep(0b0'111111111111111'0000000000000000000000000000000000000000000000000000000000000000_u96)
.is_nan());
EXPECT_TRUE( // NAN : Pseudo Not a Number
Rep(0b0'111111111111111'0000000000000000000000000000000000000000000000000000000000000001_u96)
.is_nan());
EXPECT_TRUE( // NAN : Pseudo Not a Number
Rep(0b0'111111111111111'0100000000000000000000000000000000000000000000000000000000000000_u96)
.is_nan());
EXPECT_TRUE( // NAN : Signalling Not a Number
Rep(0b0'111111111111111'1000000000000000000000000000000000000000000000000000000000000001_u96)
.is_nan());
EXPECT_TRUE( // NAN : Floating-point Indefinite
Rep(0b0'111111111111111'1100000000000000000000000000000000000000000000000000000000000000_u96)
.is_nan());
EXPECT_TRUE( // NAN : Quiet Not a Number
Rep(0b0'111111111111111'1100000000000000000000000000000000000000000000000000000000000001_u96)
.is_nan());
EXPECT_TRUE( // NAN : Unnormal
Rep(0b0'111111111111110'0000000000000000000000000000000000000000000000000000000000000000_u96)
.is_nan());
EXPECT_FALSE( // Zero
Rep(0b0'000000000000000'0000000000000000000000000000000000000000000000000000000000000000_u96)
.is_nan());
EXPECT_FALSE( // Subnormal
Rep(0b0'000000000000000'0000000000000000000000000000000000000000000000000000000000000001_u96)
.is_nan());
EXPECT_FALSE( // Pseudo Denormal
Rep(0b0'000000000000000'1000000000000000000000000000000000000000000000000000000000000001_u96)
.is_nan());
EXPECT_FALSE( // Infinity
Rep(0b0'111111111111111'1000000000000000000000000000000000000000000000000000000000000000_u96)
.is_nan());
EXPECT_FALSE( // Normalized
Rep(0b0'111111111111110'1000000000000000000000000000000000000000000000000000000000000000_u96)
.is_nan());
#else
#error "unhandled long double type"
#endif
}

enum class FP {
Expand Down Expand Up @@ -430,6 +506,7 @@ TEST(LlvmLibcFPBitsTest, DoubleType) {
#ifdef LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80
TEST(LlvmLibcFPBitsTest, X86LongDoubleType) {
using LongDoubleBits = FPBits<long double>;
using Rep = FPRep<FPType::X86_Binary80>;

EXPECT_STREQ(LIBC_NAMESPACE::str(LongDoubleBits::inf(Sign::POS)).c_str(),
"(+Infinity)");
Expand All @@ -441,62 +518,117 @@ TEST(LlvmLibcFPBitsTest, X86LongDoubleType) {
LongDoubleBits zero(0.0l);
EXPECT_TRUE(zero.is_pos());
EXPECT_EQ(zero.get_biased_exponent(), 0_u16);
EXPECT_EQ(zero.get_mantissa(), 0_u128);
EXPECT_EQ(zero.uintval(), 0_u128);
EXPECT_EQ(zero.get_mantissa(), LongDoubleBits::StorageType(Rep::zero()));
EXPECT_EQ(zero.uintval(), LongDoubleBits::StorageType(Rep::zero()));
#if __SIZEOF_LONG_DOUBLE__ == 16
EXPECT_STREQ(
LIBC_NAMESPACE::str(zero).c_str(),
"0x00000000000000000000000000000000 = "
"(S: 0, E: 0x0000, I: 0, M: 0x00000000000000000000000000000000)");
#elif __SIZEOF_LONG_DOUBLE__ == 12
EXPECT_STREQ(LIBC_NAMESPACE::str(zero).c_str(),
"0x000000000000000000000000 = "
"(S: 0, E: 0x0000, I: 0, M: 0x000000000000000000000000)");
#else
#error "unhandled long double type"
#endif

LongDoubleBits negzero(-0.0l);
EXPECT_TRUE(negzero.is_neg());
EXPECT_EQ(negzero.get_biased_exponent(), 0_u16);
EXPECT_EQ(negzero.get_mantissa(), 0_u128);
EXPECT_EQ(negzero.get_mantissa(), LongDoubleBits::StorageType(Rep::zero()));
#if __SIZEOF_LONG_DOUBLE__ == 16
EXPECT_EQ(negzero.uintval(), 0x8000'00000000'00000000_u128);
EXPECT_STREQ(
LIBC_NAMESPACE::str(negzero).c_str(),
"0x00000000000080000000000000000000 = "
"(S: 1, E: 0x0000, I: 0, M: 0x00000000000000000000000000000000)");
#elif __SIZEOF_LONG_DOUBLE__ == 12
EXPECT_EQ(negzero.uintval(), 0x8000'00000000'00000000_u96);
EXPECT_STREQ(LIBC_NAMESPACE::str(negzero).c_str(),
"0x000080000000000000000000 = "
"(S: 1, E: 0x0000, I: 0, M: 0x000000000000000000000000)");
#else
#error "unhandled long double type"
#endif

LongDoubleBits one(1.0l);
EXPECT_TRUE(one.is_pos());
EXPECT_EQ(one.get_biased_exponent(), 0x3FFF_u16);
EXPECT_EQ(one.get_mantissa(), 0_u128);
EXPECT_EQ(one.get_mantissa(), LongDoubleBits::StorageType(Rep::zero()));
#if __SIZEOF_LONG_DOUBLE__ == 16
EXPECT_EQ(one.uintval(), 0x3FFF'80000000'00000000_u128);
EXPECT_STREQ(
LIBC_NAMESPACE::str(one).c_str(),
"0x0000000000003FFF8000000000000000 = "
"(S: 0, E: 0x3FFF, I: 1, M: 0x00000000000000000000000000000000)");
#elif __SIZEOF_LONG_DOUBLE__ == 12
EXPECT_EQ(one.uintval(), 0x3FFF'80000000'00000000_u96);
EXPECT_STREQ(LIBC_NAMESPACE::str(one).c_str(),
"0x00003FFF8000000000000000 = "
"(S: 0, E: 0x3FFF, I: 1, M: 0x000000000000000000000000)");
#else
#error "unhandled long double type"
#endif

LongDoubleBits negone(-1.0l);
EXPECT_TRUE(negone.is_neg());
EXPECT_EQ(negone.get_biased_exponent(), 0x3FFF_u16);
EXPECT_EQ(negone.get_mantissa(), 0_u128);
EXPECT_EQ(negone.get_mantissa(), LongDoubleBits::StorageType(Rep::zero()));
#if __SIZEOF_LONG_DOUBLE__ == 16
EXPECT_EQ(negone.uintval(), 0xBFFF'80000000'00000000_u128);
EXPECT_STREQ(
LIBC_NAMESPACE::str(negone).c_str(),
"0x000000000000BFFF8000000000000000 = "
"(S: 1, E: 0x3FFF, I: 1, M: 0x00000000000000000000000000000000)");
#elif __SIZEOF_LONG_DOUBLE__ == 12
EXPECT_EQ(negone.uintval(), 0xBFFF'80000000'00000000_u96);
EXPECT_STREQ(LIBC_NAMESPACE::str(negone).c_str(),
"0x0000BFFF8000000000000000 = "
"(S: 1, E: 0x3FFF, I: 1, M: 0x000000000000000000000000)");
#else
#error "unhandled long double type"
#endif

LongDoubleBits num(1.125l);
EXPECT_TRUE(num.is_pos());
EXPECT_EQ(num.get_biased_exponent(), 0x3FFF_u16);
#if __SIZEOF_LONG_DOUBLE__ == 16
EXPECT_EQ(num.get_mantissa(), 0x10000000'00000000_u128);
EXPECT_EQ(num.uintval(), 0x3FFF'90000000'00000000_u128);
EXPECT_STREQ(
LIBC_NAMESPACE::str(num).c_str(),
"0x0000000000003FFF9000000000000000 = "
"(S: 0, E: 0x3FFF, I: 1, M: 0x00000000000000001000000000000000)");
#elif __SIZEOF_LONG_DOUBLE__ == 12
EXPECT_EQ(num.get_mantissa(), 0x10000000'00000000_u96);
EXPECT_EQ(num.uintval(), 0x3FFF'90000000'00000000_u96);
EXPECT_STREQ(LIBC_NAMESPACE::str(num).c_str(),
"0x00003FFF9000000000000000 = "
"(S: 0, E: 0x3FFF, I: 1, M: 0x000000001000000000000000)");
#else
#error "unhandled long double type"
#endif

LongDoubleBits negnum(-1.125l);
EXPECT_TRUE(negnum.is_neg());
EXPECT_EQ(negnum.get_biased_exponent(), 0x3FFF_u16);
#if __SIZEOF_LONG_DOUBLE__ == 16
EXPECT_EQ(negnum.get_mantissa(), 0x10000000'00000000_u128);
EXPECT_EQ(negnum.uintval(), 0xBFFF'90000000'00000000_u128);
EXPECT_STREQ(
LIBC_NAMESPACE::str(negnum).c_str(),
"0x000000000000BFFF9000000000000000 = "
"(S: 1, E: 0x3FFF, I: 1, M: 0x00000000000000001000000000000000)");
#elif __SIZEOF_LONG_DOUBLE__ == 12
EXPECT_EQ(negnum.get_mantissa(), 0x10000000'00000000_u96);
EXPECT_EQ(negnum.uintval(), 0xBFFF'90000000'00000000_u96);
EXPECT_STREQ(LIBC_NAMESPACE::str(negnum).c_str(),
"0x0000BFFF9000000000000000 = "
"(S: 1, E: 0x3FFF, I: 1, M: 0x000000001000000000000000)");
#else
#error "unhandled long double type"
#endif

LongDoubleBits quiet_nan = LongDoubleBits::quiet_nan();
EXPECT_EQ(quiet_nan.is_quiet_nan(), true);
Expand Down
8 changes: 8 additions & 0 deletions libc/test/src/__support/big_int_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1067,4 +1067,12 @@ TEST(LlvmLibcUIntClassTest, SignedOtherWordTypeCastTests) {
ASSERT_TRUE(bigger_back_plus_a + bigger_back_minus_a == zero_96);
}

TEST(LlvmLibcUIntClassTest, MixedSignednessOtherWordTypeCastTests) {
using LL_UInt96 = BigInt<96, false, uint32_t>;
LL_UInt96 x = -123;
// ensure that -123 gets extended, even though the input type is signed while
// the BigInt is unsigned.
ASSERT_EQ(int64_t(x), int64_t(-123));
}

} // namespace LIBC_NAMESPACE_DECL
11 changes: 11 additions & 0 deletions libc/test/src/__support/str_to_long_double_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,23 @@ TEST_F(LlvmLibcStrToLongDblTest, EiselLemireFloat80Simple) {
}

TEST_F(LlvmLibcStrToLongDblTest, EiselLemireFloat80LongerMantissa) {
#if __SIZEOF_LONG_DOUBLE__ == 16
eisel_lemire_test(0x12345678'12345678'12345678'12345678_u128, 0,
0x91a2b3c091a2b3c1, 16507);
eisel_lemire_test(0x12345678'12345678'12345678'12345678_u128, 300,
0xd97757de56adb65c, 17503);
eisel_lemire_test(0x12345678'12345678'12345678'12345678_u128, -300,
0xc30feb9a7618457d, 15510);
#elif __SIZEOF_LONG_DOUBLE__ == 12
eisel_lemire_test(0x12345678'12345678'12345678_u96, 0, 0x91a2b3c091a2b3c1,
16475);
eisel_lemire_test(0x12345678'12345678'12345678_u96, 300, 0xd97757de56adb65c,
17471);
eisel_lemire_test(0x12345678'12345678'12345678_u96, -300, 0xc30feb9a7618457d,
15478);
#else
#error "unhandled long double type"
#endif
}

// These tests check numbers at the edge of the DETAILED_POWERS_OF_TEN table.
Expand Down
77 changes: 77 additions & 0 deletions libc/test/src/math/smoke/CanonicalizeTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,18 @@

#include "hdr/math_macros.h"

#if __SIZEOF_LONG_DOUBLE__ != 16 && __SIZEOF_LONG_DOUBLE__ != 12
#error "unhandled long double type"
#endif

#define TEST_SPECIAL(x, y, expected, expected_exception) \
EXPECT_EQ(expected, f(&x, &y)); \
EXPECT_FP_EXCEPTION(expected_exception); \
LIBC_NAMESPACE::fputil::clear_except(FE_ALL_EXCEPT)

#define TEST_REGULAR(x, y, expected) TEST_SPECIAL(x, y, expected, 0)

using LIBC_NAMESPACE::operator""_u96;
using LIBC_NAMESPACE::operator""_u128;

template <typename T>
Expand Down Expand Up @@ -61,53 +66,89 @@ class CanonicalizeTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
// Exponent | Significand | Meaning
// | Bits 63-62 | Bits 61-0 |
// All Ones | 00 | Zero | Pseudo Infinity, Value = SNaN
#if __SIZEOF_LONG_DOUBLE__ == 16
FPBits test1(0x00000000'00007FFF'00000000'00000000_u128);
#elif __SIZEOF_LONG_DOUBLE__ == 12
FPBits test1(0x00007FFF'00000000'00000000_u96);
#endif
const T test1_val = test1.get_val();
TEST_SPECIAL(cx, test1_val, 1, FE_INVALID);
EXPECT_FP_EQ(cx, aNaN);

// Exponent | Significand | Meaning
// | Bits 63-62 | Bits 61-0 |
// All Ones | 00 | Non-Zero | Pseudo NaN, Value = SNaN
#if __SIZEOF_LONG_DOUBLE__ == 16
FPBits test2_1(0x00000000'00007FFF'00000000'00000001_u128);
#elif __SIZEOF_LONG_DOUBLE__ == 12
FPBits test2_1(0x00007FFF'00000000'00000001_u96);
#endif
const T test2_1_val = test2_1.get_val();
TEST_SPECIAL(cx, test2_1_val, 1, FE_INVALID);
EXPECT_FP_EQ(cx, aNaN);

#if __SIZEOF_LONG_DOUBLE__ == 16
FPBits test2_2(0x00000000'00007FFF'00000042'70000001_u128);
#elif __SIZEOF_LONG_DOUBLE__ == 12
FPBits test2_2(0x00007FFF'00000042'70000001_u96);
#endif
const T test2_2_val = test2_2.get_val();
TEST_SPECIAL(cx, test2_2_val, 1, FE_INVALID);
EXPECT_FP_EQ(cx, aNaN);

#if __SIZEOF_LONG_DOUBLE__ == 16
FPBits test2_3(0x00000000'00007FFF'00000000'08261001_u128);
#elif __SIZEOF_LONG_DOUBLE__ == 12
FPBits test2_3(0x00007FFF'00000000'08261001_u96);
#endif
const T test2_3_val = test2_3.get_val();
TEST_SPECIAL(cx, test2_3_val, 1, FE_INVALID);
EXPECT_FP_EQ(cx, aNaN);

#if __SIZEOF_LONG_DOUBLE__ == 16
FPBits test2_4(0x00000000'00007FFF'00007800'08261001_u128);
#elif __SIZEOF_LONG_DOUBLE__ == 12
FPBits test2_4(0x00007FFF'00007800'08261001_u96);
#endif
const T test2_4_val = test2_4.get_val();
TEST_SPECIAL(cx, test2_4_val, 1, FE_INVALID);
EXPECT_FP_EQ(cx, aNaN);

// Exponent | Significand | Meaning
// | Bits 63-62 | Bits 61-0 |
// All Ones | 01 | Anything | Pseudo NaN, Value = SNaN
#if __SIZEOF_LONG_DOUBLE__ == 16
FPBits test3_1(0x00000000'00007FFF'40000000'00000000_u128);
#elif __SIZEOF_LONG_DOUBLE__ == 12
FPBits test3_1(0x00007FFF'40000000'00000000_u96);
#endif
const T test3_1_val = test3_1.get_val();
TEST_SPECIAL(cx, test3_1_val, 1, FE_INVALID);
EXPECT_FP_EQ(cx, aNaN);

#if __SIZEOF_LONG_DOUBLE__ == 16
FPBits test3_2(0x00000000'00007FFF'40000042'70000001_u128);
#elif __SIZEOF_LONG_DOUBLE__ == 12
FPBits test3_2(0x00007FFF'40000042'70000001_u96);
#endif
const T test3_2_val = test3_2.get_val();
TEST_SPECIAL(cx, test3_2_val, 1, FE_INVALID);
EXPECT_FP_EQ(cx, aNaN);

#if __SIZEOF_LONG_DOUBLE__ == 16
FPBits test3_3(0x00000000'00007FFF'40000000'08261001_u128);
#elif __SIZEOF_LONG_DOUBLE__ == 12
FPBits test3_3(0x00007FFF'40000000'08261001_u96);
#endif
const T test3_3_val = test3_3.get_val();
TEST_SPECIAL(cx, test3_3_val, 1, FE_INVALID);
EXPECT_FP_EQ(cx, aNaN);

#if __SIZEOF_LONG_DOUBLE__ == 16
FPBits test3_4(0x00000000'00007FFF'40007800'08261001_u128);
#elif __SIZEOF_LONG_DOUBLE__ == 12
FPBits test3_4(0x00007FFF'40007800'08261001_u96);
#endif
const T test3_4_val = test3_4.get_val();
TEST_SPECIAL(cx, test3_4_val, 1, FE_INVALID);
EXPECT_FP_EQ(cx, aNaN);
Expand All @@ -116,19 +157,31 @@ class CanonicalizeTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
// | Bit 63 | Bits 62-0 |
// All zeroes | One | Anything | Pseudo Denormal, Value =
// | | | (−1)**s × m × 2**−16382
#if __SIZEOF_LONG_DOUBLE__ == 16
FPBits test4_1(0x00000000'00000000'80000000'00000000_u128);
#elif __SIZEOF_LONG_DOUBLE__ == 12
FPBits test4_1(0x00000000'80000000'00000000_u96);
#endif
const T test4_1_val = test4_1.get_val();
TEST_SPECIAL(cx, test4_1_val, 0, 0);
EXPECT_FP_EQ(
cx, FPBits::make_value(test4_1.get_explicit_mantissa(), 0).get_val());

#if __SIZEOF_LONG_DOUBLE__ == 16
FPBits test4_2(0x00000000'00000000'80000042'70000001_u128);
#elif __SIZEOF_LONG_DOUBLE__ == 12
FPBits test4_2(0x00000000'80000042'70000001_u96);
#endif
const T test4_2_val = test4_2.get_val();
TEST_SPECIAL(cx, test4_2_val, 0, 0);
EXPECT_FP_EQ(
cx, FPBits::make_value(test4_2.get_explicit_mantissa(), 0).get_val());

#if __SIZEOF_LONG_DOUBLE__ == 16
FPBits test4_3(0x00000000'00000000'80000000'08261001_u128);
#elif __SIZEOF_LONG_DOUBLE__ == 12
FPBits test4_3(0x00000000'80000000'08261001_u96);
#endif
const T test4_3_val = test4_3.get_val();
TEST_SPECIAL(cx, test4_3_val, 0, 0);
EXPECT_FP_EQ(
Expand All @@ -138,32 +191,56 @@ class CanonicalizeTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
// | Bit 63 | Bits 62-0 |
// All Other | Zero | Anything | Unnormal, Value = SNaN
// Values | | |
#if __SIZEOF_LONG_DOUBLE__ == 16
FPBits test5_1(0x00000000'00000040'00000000'00000001_u128);
#elif __SIZEOF_LONG_DOUBLE__ == 12
FPBits test5_1(0x00000040'00000000'00000001_u96);
#endif
const T test5_1_val = test5_1.get_val();
TEST_SPECIAL(cx, test5_1_val, 1, FE_INVALID);
EXPECT_FP_EQ(cx, aNaN);

#if __SIZEOF_LONG_DOUBLE__ == 16
FPBits test5_2(0x00000000'00000230'00000042'70000001_u128);
#elif __SIZEOF_LONG_DOUBLE__ == 12
FPBits test5_2(0x00000230'00000042'70000001_u96);
#endif
const T test5_2_val = test5_2.get_val();
TEST_SPECIAL(cx, test5_2_val, 1, FE_INVALID);
EXPECT_FP_EQ(cx, aNaN);

#if __SIZEOF_LONG_DOUBLE__ == 16
FPBits test5_3(0x00000000'00000560'00000000'08261001_u128);
#elif __SIZEOF_LONG_DOUBLE__ == 12
FPBits test5_3(0x00000560'00000000'08261001_u96);
#endif
const T test5_3_val = test5_3.get_val();
TEST_SPECIAL(cx, test5_3_val, 1, FE_INVALID);
EXPECT_FP_EQ(cx, aNaN);

#if __SIZEOF_LONG_DOUBLE__ == 16
FPBits test5_4(0x00000000'00000780'00000028'16000000_u128);
#elif __SIZEOF_LONG_DOUBLE__ == 12
FPBits test5_4(0x00000780'00000028'16000000_u96);
#endif
const T test5_4_val = test5_4.get_val();
TEST_SPECIAL(cx, test5_4_val, 1, FE_INVALID);
EXPECT_FP_EQ(cx, aNaN);

#if __SIZEOF_LONG_DOUBLE__ == 16
FPBits test5_5(0x00000000'00000900'00000042'70000001_u128);
#elif __SIZEOF_LONG_DOUBLE__ == 12
FPBits test5_5(0x00000900'00000042'70000001_u96);
#endif
const T test5_5_val = test5_5.get_val();
TEST_SPECIAL(cx, test5_5_val, 1, FE_INVALID);
EXPECT_FP_EQ(cx, aNaN);

#if __SIZEOF_LONG_DOUBLE__ == 16
FPBits test5_6(0x00000000'00000AB0'00000000'08261001_u128);
#elif __SIZEOF_LONG_DOUBLE__ == 12
FPBits test5_6(0x00000AB0'00000000'08261001_u96);
#endif
const T test5_6_val = test5_6.get_val();
TEST_SPECIAL(cx, test5_6_val, 1, FE_INVALID);
EXPECT_FP_EQ(cx, aNaN);
Expand Down
5 changes: 3 additions & 2 deletions libc/test/src/stdlib/strtold_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@ class LlvmLibcStrToLDTest : public LIBC_NAMESPACE::testing::Test {
// +-- 15 Exponent Bits
char *str_end = nullptr;

LIBC_NAMESPACE::fputil::FPBits<long double> expected_fp =
LIBC_NAMESPACE::fputil::FPBits<long double>(expectedRawData);
using FPBits = LIBC_NAMESPACE::fputil::FPBits<long double>;
FPBits expected_fp =
FPBits(static_cast<FPBits::StorageType>(expectedRawData));
const int expected_errno = expectedErrno;

LIBC_NAMESPACE::libc_errno = 0;
Expand Down