Skip to content

Commit 5a1594c

Browse files
committed
Merge branch 'carg' into mpc_testing_infra
2 parents fd7ccfc + c8956f6 commit 5a1594c

File tree

8 files changed

+117
-0
lines changed

8 files changed

+117
-0
lines changed

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ set(TARGET_LIBM_ENTRYPOINTS
373373
libc.src.complex.cproj
374374
libc.src.complex.cprojf
375375
libc.src.complex.cprojl
376+
libc.src.complex.cargf
376377

377378
# fenv.h entrypoints
378379
libc.src.fenv.feclearexcept

libc/src/complex/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,5 @@ add_complex_entrypoint_object(cprojf)
3636
add_complex_entrypoint_object(cprojl)
3737
add_complex_entrypoint_object(cprojf16)
3838
add_complex_entrypoint_object(cprojf128)
39+
40+
add_complex_entrypoint_object(cargf)

libc/src/complex/cargf.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//===-- Implementation header for cargf -------------------------*- C++ -*-===//
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+
#ifndef LLVM_LIBC_SRC_COMPLEX_CARGF_H
10+
#define LLVM_LIBC_SRC_COMPLEX_CARGF_H
11+
12+
#include "src/__support/macros/config.h"
13+
14+
namespace LIBC_NAMESPACE_DECL {
15+
16+
float cargf(_Complex float x);
17+
18+
} // namespace LIBC_NAMESPACE_DECL
19+
20+
#endif // LLVM_LIBC_SRC_COMPLEX_CARGF_H

libc/src/complex/generic/CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
add_entrypoint_object(
2+
cargf
3+
SRCS
4+
cargf.cpp
5+
HDRS
6+
../cargf.h
7+
COMPILE_OPTIONS
8+
${libc_opt_high_flag}
9+
DEPENDS
10+
libc.src.__support.complex_type
11+
libc.src.math.atan2f
12+
)
13+
114
add_entrypoint_object(
215
cproj
316
SRCS

libc/src/complex/generic/cargf.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//===-- Implementation of cargf function ----------------------------------===//
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/complex/cargf.h"
10+
#include "src/__support/common.h"
11+
#include "src/__support/complex_type.h"
12+
#include "src/math/atan2f.h"
13+
14+
namespace LIBC_NAMESPACE_DECL {
15+
16+
LLVM_LIBC_FUNCTION(float, cargf, (_Complex float x)) {
17+
Complex<float> x_c = cpp::bit_cast<Complex<float>>(x);
18+
return atan2f(x_c.imag, x_c.real);
19+
}
20+
21+
} // namespace LIBC_NAMESPACE_DECL

libc/test/src/complex/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
add_custom_target(libc-complex-unittests)
22

3+
add_libc_test(
4+
cargf_test
5+
SUITE
6+
libc-complex-unittests
7+
SRCS
8+
cargf_test.cpp
9+
DEPENDS
10+
libc.src.complex.cargf
11+
LINK_LIBRARIES
12+
LibcFPTestHelpers
13+
)
14+
315
add_libc_test(
416
conj_test
517
SUITE

libc/test/src/complex/CargTest.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//===-- Utility class to test different flavors of carg ---------*- C++ -*-===//
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+
#ifndef LLVM_LIBC_TEST_SRC_COMPLEX_CARGTEST_H
10+
#define LLVM_LIBC_TEST_SRC_COMPLEX_CARGTEST_H
11+
12+
#include "test/UnitTest/FEnvSafeTest.h"
13+
#include "test/UnitTest/FPMatcher.h"
14+
#include "test/UnitTest/Test.h"
15+
16+
#include "hdr/math_macros.h"
17+
18+
template <typename CFPT, typename FPT>
19+
class CargTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
20+
21+
DECLARE_SPECIAL_CONSTANTS(FPT)
22+
23+
public:
24+
typedef FPT (*CargFunc)(CFPT);
25+
26+
void testRoundedNumbers(CargFunc func) {
27+
EXPECT_FP_EQ((FPT)(1.10714871762320399284), func((CFPT)(1.0 + 2.0i)));
28+
}
29+
};
30+
31+
#define LIST_CARG_TESTS(U, T, func) \
32+
using LlvmLibcCargTest = CargTest<U, T>; \
33+
TEST_F(LlvmLibcCargTest, RoundedNumbers) { testRoundedNumbers(&func); }
34+
35+
#endif // LLVM_LIBC_TEST_SRC_COMPLEX_CARGTEST_H
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//===-- Unittests for cargf -----------------------------------------------===//
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 "CargTest.h"
10+
11+
#include "src/complex/cargf.h"
12+
13+
LIST_CARG_TESTS(_Complex float, float, LIBC_NAMESPACE::cargf)

0 commit comments

Comments
 (0)