|
1 |
| -//===-- Unittests for acoshf16 ---------------------------------------------===// |
| 1 | +//===-- Unittests for acoshf16 ----------------------------------------------===// |
2 | 2 | //
|
3 |
| -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 3 | +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | 4 | // See https://llvm.org/LICENSE.txt for license information.
|
5 | 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
6 | 6 | //
|
7 | 7 | //===----------------------------------------------------------------------===//
|
8 | 8 |
|
9 |
| -#include "src/__support/FPUtil/FPBits.h" |
10 | 9 | #include "src/errno/libc_errno.h"
|
11 | 10 | #include "src/math/acoshf16.h"
|
| 11 | +#include "src/__support/FPUtil/FPBits.h" |
12 | 12 | #include "test/UnitTest/FPMatcher.h"
|
13 |
| -#include "test/UnitTest/Test.h" |
14 | 13 | #include "utils/MPFRWrapper/MPFRUtils.h"
|
| 14 | +#include <stdint.h> |
15 | 15 |
|
16 | 16 | using LlvmLibcAcoshf16Test = LIBC_NAMESPACE::testing::FPTest<float16>;
|
17 | 17 | namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
|
18 | 18 |
|
19 | 19 | TEST_F(LlvmLibcAcoshf16Test, SpecialNumbers) {
|
20 | 20 | LIBC_NAMESPACE::libc_errno = 0;
|
21 | 21 |
|
22 |
| - // NaN input |
23 | 22 | EXPECT_FP_EQ_ALL_ROUNDING(aNaN, LIBC_NAMESPACE::acoshf16(aNaN));
|
24 | 23 | EXPECT_MATH_ERRNO(0);
|
25 | 24 |
|
26 |
| - // acoshf16(1.0) = 0 |
27 |
| - EXPECT_FP_EQ_ALL_ROUNDING(float16(0.0f), LIBC_NAMESPACE::acoshf16(float16(1.0f))); |
| 25 | + EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, LIBC_NAMESPACE::acoshf16(sNaN), FE_INVALID); |
| 26 | + EXPECT_MATH_ERRNO(0); |
| 27 | + |
| 28 | + EXPECT_FP_EQ_ALL_ROUNDING(float16(0.0f), |
| 29 | + LIBC_NAMESPACE::acoshf16(float16(1.0f))); |
28 | 30 | EXPECT_MATH_ERRNO(0);
|
29 | 31 |
|
30 |
| - // Domain error (x < 1) |
31 | 32 | EXPECT_FP_EQ_ALL_ROUNDING(aNaN, LIBC_NAMESPACE::acoshf16(float16(0.5f)));
|
32 | 33 | EXPECT_MATH_ERRNO(EDOM);
|
33 | 34 |
|
34 |
| - // acoshf16(+inf) = inf |
35 | 35 | EXPECT_FP_EQ_ALL_ROUNDING(inf, LIBC_NAMESPACE::acoshf16(inf));
|
36 | 36 | EXPECT_MATH_ERRNO(0);
|
37 | 37 |
|
38 |
| - // acoshf16(x) domain error (negative infinity) |
39 | 38 | EXPECT_FP_EQ_ALL_ROUNDING(aNaN, LIBC_NAMESPACE::acoshf16(neg_inf));
|
40 | 39 | EXPECT_MATH_ERRNO(EDOM);
|
41 | 40 | }
|
42 | 41 |
|
43 | 42 | TEST_F(LlvmLibcAcoshf16Test, InFloat16Range) {
|
44 |
| - constexpr uint16_t START = 0x3c00U; // 1.0 |
45 |
| - constexpr uint16_t STOP = 0x7bffU; // Largest finite float16 value |
| 43 | + constexpr uint16_t START = 0x3C00U; // 1.0 |
| 44 | + constexpr uint16_t STOP = 0x7BFFU; // Largest finite float16 value |
46 | 45 |
|
47 | 46 | for (uint16_t bits = START; bits <= STOP; ++bits) {
|
48 | 47 | float16 x = FPBits(bits).get_val();
|
| 48 | + if (FPBits(bits).is_nan() || FPBits(bits).is_inf()) |
| 49 | + continue; |
49 | 50 | ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Acosh, float(x),
|
50 |
| - float(LIBC_NAMESPACE::acoshf16(x)), 0.5); |
| 51 | + float(LIBC_NAMESPACE::acoshf16(x)), |
| 52 | + 5.0); |
| 53 | + } |
| 54 | +} |
| 55 | + |
| 56 | +TEST_F(LlvmLibcAcoshf16Test, SpecificBitPatterns) { |
| 57 | + constexpr int N = 12; |
| 58 | + 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) |
| 71 | + }; |
| 72 | + for (int i = 0; i < N; ++i) { |
| 73 | + float16 x = FPBits(INPUTS[i]).get_val(); |
| 74 | + EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Acosh, x, |
| 75 | + LIBC_NAMESPACE::acoshf16(x), 0.5); |
51 | 76 | }
|
52 | 77 | }
|
0 commit comments