|
6 | 6 | // |
7 | 7 | //===----------------------------------------------------------------------===// |
8 | 8 |
|
| 9 | +#include "src/__support/FPUtil/cast.h" |
9 | 10 | #include "src/errno/libc_errno.h" |
10 | 11 | #include "src/math/acoshf16.h" |
11 | 12 | #include "src/__support/FPUtil/FPBits.h" |
@@ -40,34 +41,38 @@ TEST_F(LlvmLibcAcoshf16Test, SpecialNumbers) { |
40 | 41 | } |
41 | 42 |
|
42 | 43 | TEST_F(LlvmLibcAcoshf16Test, InFloat16Range) { |
43 | | - constexpr uint16_t START = 0x3C00U; // 1.0 |
44 | | - constexpr uint16_t STOP = 0x7BFFU; // Largest finite float16 value |
| 44 | + constexpr uint32_t COUNT = 100'000; |
| 45 | + constexpr uint32_t STEP = UINT32_MAX / COUNT; |
45 | 46 |
|
46 | | - for (uint16_t bits = START; bits <= STOP; ++bits) { |
47 | | - float16 x = FPBits(bits).get_val(); |
48 | | - if (FPBits(bits).is_nan() || FPBits(bits).is_inf()) |
| 47 | + for (uint32_t i = 0, v = 0; i <= COUNT; ++i, v += STEP) { |
| 48 | + LIBC_NAMESPACE::fputil::FPBits<float> bits(v); |
| 49 | + float xf32 = bits.get_val(); |
| 50 | + if (bits.is_nan() || bits.is_inf()) |
49 | 51 | continue; |
50 | | - ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Acosh, float(x), |
51 | | - float(LIBC_NAMESPACE::acoshf16(x)), |
52 | | - 5.0); |
| 52 | + if (xf32 < 1.0f) |
| 53 | + continue; |
| 54 | + float16 xh = LIBC_NAMESPACE::fputil::cast<float16>(xf32); |
| 55 | + |
| 56 | + EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Acosh, xh, |
| 57 | + LIBC_NAMESPACE::acoshf16(xh), 3.0); |
53 | 58 | } |
54 | 59 | } |
55 | 60 |
|
56 | 61 | TEST_F(LlvmLibcAcoshf16Test, SpecificBitPatterns) { |
57 | 62 | constexpr int N = 12; |
58 | 63 | constexpr uint16_t INPUTS[N] = { |
59 | | - 0x3C00, // 1.0 |
60 | | - 0x3C01, // just above 1.0 (minimally larger than 1) |
61 | | - 0x3E00, // 1.5 |
62 | | - 0x4200, // 3.0 |
63 | | - 0x4500, // 5.0 |
64 | | - 0x4900, // 10.0 |
65 | | - 0x51FF, // ~47.94 (random mid-range value) |
66 | | - 0x5CB0, // ~300.0 (random mid-range value) |
67 | | - 0x643F, // ~1087.6 (random large value) |
68 | | - 0x77FF, // just below next exponent interval (max for exponent 0x1D) |
69 | | - 0x7801, // just above previous value (min for exponent 0x1E) |
70 | | - 0x7BFF // 65504.0 (max finite half) |
| 64 | + 0x3C00, // x = 1.0 |
| 65 | + 0x3C01, // x = just above 1.0 (minimally larger than 1) |
| 66 | + 0x3E00, // x = 1.5 |
| 67 | + 0x4200, // x = 3.0 |
| 68 | + 0x4500, // x = 5.0 |
| 69 | + 0x4900, // x = 10.0 |
| 70 | + 0x51FF, // x = ~47.94 |
| 71 | + 0x5CB0, // x = ~300.0 |
| 72 | + 0x643F, // x = ~1087.6 |
| 73 | + 0x77FF, // x = just below next exponent interval (max for exponent 0x1D) |
| 74 | + 0x7801, // x = just above previous value (min for exponent 0x1E) |
| 75 | + 0x7BFF // x = 65504.0 (max finite half) |
71 | 76 | }; |
72 | 77 | for (int i = 0; i < N; ++i) { |
73 | 78 | float16 x = FPBits(INPUTS[i]).get_val(); |
|
0 commit comments