1//===-- Unittests for atanf -----------------------------------------------===//
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/atanf.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 LlvmLibcAtanfTest = LIBC_NAMESPACE::testing::FPTest<float>;
21
22namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
23
24TEST_F(LlvmLibcAtanfTest, SpecialNumbers) {
25 LIBC_NAMESPACE::libc_errno = 0;
26 LIBC_NAMESPACE::fputil::clear_except(FE_ALL_EXCEPT);
27 EXPECT_FP_EQ_ALL_ROUNDING(aNaN, LIBC_NAMESPACE::atanf(aNaN));
28 EXPECT_FP_EXCEPTION(0);
29 EXPECT_MATH_ERRNO(0);
30
31 LIBC_NAMESPACE::fputil::clear_except(FE_ALL_EXCEPT);
32 EXPECT_FP_EQ_ALL_ROUNDING(0.0f, LIBC_NAMESPACE::atanf(0.0f));
33 EXPECT_FP_EXCEPTION(0);
34 EXPECT_MATH_ERRNO(0);
35
36 LIBC_NAMESPACE::fputil::clear_except(FE_ALL_EXCEPT);
37 EXPECT_FP_EQ_ALL_ROUNDING(-0.0f, LIBC_NAMESPACE::atanf(-0.0f));
38 EXPECT_FP_EXCEPTION(0);
39 EXPECT_MATH_ERRNO(0);
40}
41
42TEST_F(LlvmLibcAtanfTest, InFloatRange) {
43 constexpr uint32_t COUNT = 100'000;
44 const uint32_t STEP = FPBits(inf).uintval() / COUNT;
45 for (uint32_t i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
46 float x = FPBits(v).get_val();
47 EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Atan, x,
48 LIBC_NAMESPACE::atanf(x), 0.5);
49 EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Atan, -x,
50 LIBC_NAMESPACE::atanf(-x), 0.5);
51 }
52}
53
54// For small values, tanh(x) is x.
55TEST_F(LlvmLibcAtanfTest, SpecialValues) {
56 uint32_t val_arr[] = {
57 0x3d8d6b23U, // x = 0x1.1ad646p-4f
58 0x3dbb6ac7U, // x = 0x1.76d58ep-4f
59 0x3feefcfbU, // x = 0x1.ddf9f6p+0f
60 0x3ffe2ec1U, // x = 0x1.fc5d82p+0f
61 0xbd8d6b23U, // x = -0x1.1ad646p-4f
62 0xbdbb6ac7U, // x = -0x1.76d58ep-4f
63 0xbfeefcfbU, // x = -0x1.ddf9f6p+0f
64 0xbffe2ec1U, // x = -0x1.fc5d82p+0
65 0x7F800000U, // x = +Inf
66 0xFF800000U, // x = -Inf
67 };
68 for (uint32_t v : val_arr) {
69 float x = FPBits(v).get_val();
70 EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Atan, x,
71 LIBC_NAMESPACE::atanf(x), 0.5);
72 }
73}
74

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