1//===-- Unittests for acoshf ----------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "hdr/math_macros.h"
10#include "src/__support/FPUtil/FPBits.h"
11#include "src/errno/libc_errno.h"
12#include "src/math/acoshf.h"
13#include "test/UnitTest/FPMatcher.h"
14#include "test/UnitTest/Test.h"
15#include "utils/MPFRWrapper/MPFRUtils.h"
16
17#include <errno.h>
18#include <stdint.h>
19
20using LlvmLibcAcoshfTest = LIBC_NAMESPACE::testing::FPTest<float>;
21
22namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
23
24TEST_F(LlvmLibcAcoshfTest, SpecialNumbers) {
25 LIBC_NAMESPACE::libc_errno = 0;
26
27 EXPECT_FP_EQ_ALL_ROUNDING(aNaN, LIBC_NAMESPACE::acoshf(aNaN));
28 EXPECT_MATH_ERRNO(0);
29
30 EXPECT_FP_EQ_ALL_ROUNDING(aNaN, LIBC_NAMESPACE::acoshf(0.0f));
31 EXPECT_MATH_ERRNO(EDOM);
32
33 EXPECT_FP_EQ_ALL_ROUNDING(0.0f, LIBC_NAMESPACE::acoshf(1.0f));
34 EXPECT_MATH_ERRNO(0);
35
36 EXPECT_FP_EQ_ALL_ROUNDING(inf, LIBC_NAMESPACE::acoshf(inf));
37 EXPECT_MATH_ERRNO(0);
38
39 EXPECT_FP_EQ_ALL_ROUNDING(aNaN, LIBC_NAMESPACE::acoshf(neg_inf));
40 EXPECT_MATH_ERRNO(EDOM);
41}
42
43TEST_F(LlvmLibcAcoshfTest, InFloatRange) {
44 constexpr uint32_t COUNT = 100'000;
45 constexpr uint32_t STEP = UINT32_MAX / COUNT;
46 for (uint32_t i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
47 float x = FPBits(v).get_val();
48 if (isnan(x: x) || isinf(x: x))
49 continue;
50 ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Acosh, x,
51 LIBC_NAMESPACE::acoshf(x), 0.5);
52 }
53}
54
55TEST_F(LlvmLibcAcoshfTest, SpecificBitPatterns) {
56 constexpr int N = 12;
57 constexpr uint32_t INPUTS[N] = {
58 0x3f800000, // x = 1.0f
59 0x45abaf26, // x = 0x1.575e4cp12f
60 0x49d29048, // x = 0x1.a5209p20f
61 0x4bdd65a5, // x = 0x1.bacb4ap24f
62 0x4c803f2c, // x = 0x1.007e58p26f
63 0x4f8ffb03, // x = 0x1.1ff606p32f
64 0x5c569e88, // x = 0x1.ad3d1p57f
65 0x5e68984e, // x = 0x1.d1309cp61f
66 0x655890d3, // x = 0x1.b121a6p75f
67 0x65de7ca6, // x = 0x1.bcf94cp76f
68 0x6eb1a8ec, // x = 0x1.6351d8p94f
69 0x7997f30a, // x = 0x1.2fe614p116f
70 };
71
72 for (int i = 0; i < N; ++i) {
73 float x = FPBits(INPUTS[i]).get_val();
74 EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Acosh, x,
75 LIBC_NAMESPACE::acoshf(x), 0.5);
76 }
77}
78

source code of libc/test/src/math/acoshf_test.cpp