Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 54 additions & 58 deletions libc/test/src/math/smoke/CanonicalizeTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@

#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); \
Expand Down Expand Up @@ -66,10 +62,10 @@ 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
#if __SIZEOF_LONG_DOUBLE__ == 12
FPBits test1(0x00007FFF'00000000'00000000_u96);
#else
FPBits test1(0x00000000'00007FFF'00000000'00000000_u128);
#endif
const T test1_val = test1.get_val();
TEST_SPECIAL(cx, test1_val, 1, FE_INVALID);
Expand All @@ -78,37 +74,37 @@ class CanonicalizeTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
// 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
#if __SIZEOF_LONG_DOUBLE__ == 12
FPBits test2_1(0x00007FFF'00000000'00000001_u96);
#else
FPBits test2_1(0x00000000'00007FFF'00000000'00000001_u128);
#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
#if __SIZEOF_LONG_DOUBLE__ == 12
FPBits test2_2(0x00007FFF'00000042'70000001_u96);
#else
FPBits test2_2(0x00000000'00007FFF'00000042'70000001_u128);
#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
#if __SIZEOF_LONG_DOUBLE__ == 12
FPBits test2_3(0x00007FFF'00000000'08261001_u96);
#else
FPBits test2_3(0x00000000'00007FFF'00000000'08261001_u128);
#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
#if __SIZEOF_LONG_DOUBLE__ == 12
FPBits test2_4(0x00007FFF'00007800'08261001_u96);
#else
FPBits test2_4(0x00000000'00007FFF'00007800'08261001_u128);
#endif
const T test2_4_val = test2_4.get_val();
TEST_SPECIAL(cx, test2_4_val, 1, FE_INVALID);
Expand All @@ -117,37 +113,37 @@ class CanonicalizeTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
// 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
#if __SIZEOF_LONG_DOUBLE__ == 12
FPBits test3_1(0x00007FFF'40000000'00000000_u96);
#else
FPBits test3_1(0x00000000'00007FFF'40000000'00000000_u128);
#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
#if __SIZEOF_LONG_DOUBLE__ == 12
FPBits test3_2(0x00007FFF'40000042'70000001_u96);
#else
FPBits test3_2(0x00000000'00007FFF'40000042'70000001_u128);
#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
#if __SIZEOF_LONG_DOUBLE__ == 12
FPBits test3_3(0x00007FFF'40000000'08261001_u96);
#else
FPBits test3_3(0x00000000'00007FFF'40000000'08261001_u128);
#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
#if __SIZEOF_LONG_DOUBLE__ == 12
FPBits test3_4(0x00007FFF'40007800'08261001_u96);
#else
FPBits test3_4(0x00000000'00007FFF'40007800'08261001_u128);
#endif
const T test3_4_val = test3_4.get_val();
TEST_SPECIAL(cx, test3_4_val, 1, FE_INVALID);
Expand All @@ -157,30 +153,30 @@ 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
#if __SIZEOF_LONG_DOUBLE__ == 12
FPBits test4_1(0x00000000'80000000'00000000_u96);
#else
FPBits test4_1(0x00000000'00000000'80000000'00000000_u128);
#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
#if __SIZEOF_LONG_DOUBLE__ == 12
FPBits test4_2(0x00000000'80000042'70000001_u96);
#else
FPBits test4_2(0x00000000'00000000'80000042'70000001_u128);
#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
#if __SIZEOF_LONG_DOUBLE__ == 12
FPBits test4_3(0x00000000'80000000'08261001_u96);
#else
FPBits test4_3(0x00000000'00000000'80000000'08261001_u128);
#endif
const T test4_3_val = test4_3.get_val();
TEST_SPECIAL(cx, test4_3_val, 0, 0);
Expand All @@ -191,55 +187,55 @@ 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
#if __SIZEOF_LONG_DOUBLE__ == 12
FPBits test5_1(0x00000040'00000000'00000001_u96);
#else
FPBits test5_1(0x00000000'00000040'00000000'00000001_u128);
#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
#if __SIZEOF_LONG_DOUBLE__ == 12
FPBits test5_2(0x00000230'00000042'70000001_u96);
#else
FPBits test5_2(0x00000000'00000230'00000042'70000001_u128);
#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
#if __SIZEOF_LONG_DOUBLE__ == 12
FPBits test5_3(0x00000560'00000000'08261001_u96);
#else
FPBits test5_3(0x00000000'00000560'00000000'08261001_u128);
#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
#if __SIZEOF_LONG_DOUBLE__ == 12
FPBits test5_4(0x00000780'00000028'16000000_u96);
#else
FPBits test5_4(0x00000000'00000780'00000028'16000000_u128);
#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
#if __SIZEOF_LONG_DOUBLE__ == 12
FPBits test5_5(0x00000900'00000042'70000001_u96);
#else
FPBits test5_5(0x00000000'00000900'00000042'70000001_u128);
#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
#if __SIZEOF_LONG_DOUBLE__ == 12
FPBits test5_6(0x00000AB0'00000000'08261001_u96);
#else
FPBits test5_6(0x00000000'00000AB0'00000000'08261001_u128);
#endif
const T test5_6_val = test5_6.get_val();
TEST_SPECIAL(cx, test5_6_val, 1, FE_INVALID);
Expand Down
Loading