Skip to content

Commit bdae514

Browse files
committed
add exhaustive test for atanpif16
1 parent 9269370 commit bdae514

File tree

6 files changed

+61
-0
lines changed

6 files changed

+61
-0
lines changed

libc/test/src/math/CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2143,6 +2143,17 @@ add_fp_unittest(
21432143
libc.src.__support.FPUtil.fp_bits
21442144
)
21452145

2146+
add_fp_unittest(
2147+
atanpif16_test
2148+
NEED_MPFR
2149+
SUITE
2150+
libc-math-unittests
2151+
SRCS
2152+
atanpif16_test.cpp
2153+
DEPENDS
2154+
libc.src.math.atanpif16
2155+
)
2156+
21462157
add_fp_unittest(
21472158
fmul_test
21482159
NEED_MPFR
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//===-- Exhaustive test for atanpif16 -------------------------------------===//
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 "src/math/atanpif16.h"
10+
#include "test/UnitTest/FPMatcher.h"
11+
#include "test/UnitTest/Test.h"
12+
#include "utils/MPFRWrapper/MPFRUtils.h"
13+
14+
using LlvmLibcAtanpif16Test = LIBC_NAMESPACE::testing::FPTest<float16>;
15+
16+
namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
17+
18+
// Range: [0, Inf]
19+
static constexpr uint16_t POS_START = 0x0000U;
20+
static constexpr uint16_t POS_STOP = 0x7c00U;
21+
22+
// Range: [-Inf, 0]
23+
static constexpr uint16_t NEG_START = 0x8000U;
24+
static constexpr uint16_t NEG_STOP = 0xfc00U;
25+
26+
TEST_F(LlvmLibcAtanpif16Test, PositiveRange) {
27+
for (uint16_t v = POS_START; v <= POS_STOP; ++v) {
28+
float16 x = FPBits(v).get_val();
29+
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Atanpi, x,
30+
LIBC_NAMESPACE::atanpif16(x), 0.5);
31+
}
32+
}
33+
34+
TEST_F(LlvmLibcAtanpif16Test, NegativeRange) {
35+
for (uint16_t v = NEG_START; v <= NEG_STOP; ++v) {
36+
float16 x = FPBits(v).get_val();
37+
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Atanpi, x,
38+
LIBC_NAMESPACE::atanpif16(x), 0.5);
39+
}
40+
}

libc/utils/MPFRWrapper/MPCommon.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ MPFRNumber MPFRNumber::atanh() const {
106106
return result;
107107
}
108108

109+
MPFRNumber MPFRNumber::atanpi() const {
110+
MPFRNumber result(*this);
111+
mpfr_atanpi(result.value, value, mpfr_rounding);
112+
return result;
113+
}
114+
109115
MPFRNumber MPFRNumber::cbrt() const {
110116
MPFRNumber result(*this);
111117
mpfr_cbrt(result.value, value, mpfr_rounding);

libc/utils/MPFRWrapper/MPCommon.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ class MPFRNumber {
187187
MPFRNumber atan() const;
188188
MPFRNumber atan2(const MPFRNumber &b);
189189
MPFRNumber atanh() const;
190+
MPFRNumber atanpi() const;
190191
MPFRNumber cbrt() const;
191192
MPFRNumber ceil() const;
192193
MPFRNumber cos() const;

libc/utils/MPFRWrapper/MPFRUtils.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ unary_operation(Operation op, InputType input, unsigned int precision,
4040
return mpfrInput.atan();
4141
case Operation::Atanh:
4242
return mpfrInput.atanh();
43+
case Operation::Atanpi:
44+
return mpfrInput.atanpi();
4345
case Operation::Cbrt:
4446
return mpfrInput.cbrt();
4547
case Operation::Ceil:

libc/utils/MPFRWrapper/MPFRUtils.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ enum class Operation : int {
3232
Asinh,
3333
Atan,
3434
Atanh,
35+
Atanpi,
3536
Cbrt,
3637
Ceil,
3738
Cos,

0 commit comments

Comments
 (0)