[libc-commits] [libc] [libc][complex] Add cargf and carg functions to libc complex math (PR #204087)
via libc-commits
libc-commits at lists.llvm.org
Sun Jun 21 19:57:51 PDT 2026
https://github.com/jinge90 updated https://github.com/llvm/llvm-project/pull/204087
>From c91feea8f3fe906bbeaf6e3fc3e39571335fd238 Mon Sep 17 00:00:00 2001
From: jinge90 <ge.jin at intel.com>
Date: Tue, 16 Jun 2026 16:35:00 +0800
Subject: [PATCH 1/6] Add cargf and carg functions to libc complex math
---
libc/config/linux/aarch64/entrypoints.txt | 2 +
libc/config/linux/arm/entrypoints.txt | 2 +
libc/config/linux/riscv/entrypoints.txt | 2 +
libc/config/linux/x86_64/entrypoints.txt | 2 +
libc/include/complex.yaml | 12 +++
libc/src/complex/CMakeLists.txt | 4 +
libc/src/complex/carg.h | 20 +++++
libc/src/complex/cargf.h | 20 +++++
libc/src/complex/generic/CMakeLists.txt | 25 ++++++
libc/src/complex/generic/carg.cpp | 22 +++++
libc/src/complex/generic/cargf.cpp | 22 +++++
libc/test/src/complex/CArgTest.h | 102 ++++++++++++++++++++++
libc/test/src/complex/CMakeLists.txt | 20 +++++
libc/test/src/complex/carg_test.cpp | 13 +++
libc/test/src/complex/cargf_test.cpp | 13 +++
15 files changed, 281 insertions(+)
create mode 100644 libc/src/complex/carg.h
create mode 100644 libc/src/complex/cargf.h
create mode 100644 libc/src/complex/generic/carg.cpp
create mode 100644 libc/src/complex/generic/cargf.cpp
create mode 100644 libc/test/src/complex/CArgTest.h
create mode 100644 libc/test/src/complex/carg_test.cpp
create mode 100644 libc/test/src/complex/cargf_test.cpp
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index 5cddf3dc89799..a5785620bb4c2 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -440,6 +440,8 @@ endif()
set(TARGET_LIBM_ENTRYPOINTS
# complex.h entrypoints
+ libc.src.complex.carg
+ libc.src.complex.cargf
libc.src.complex.creal
libc.src.complex.crealf
libc.src.complex.creall
diff --git a/libc/config/linux/arm/entrypoints.txt b/libc/config/linux/arm/entrypoints.txt
index c4ac53c4925a3..d2a75f0e1c739 100644
--- a/libc/config/linux/arm/entrypoints.txt
+++ b/libc/config/linux/arm/entrypoints.txt
@@ -236,6 +236,8 @@ endif()
set(TARGET_LIBM_ENTRYPOINTS
# complex.h entrypoints
+ libc.src.complex.carg
+ libc.src.complex.cargf
libc.src.complex.creal
libc.src.complex.crealf
libc.src.complex.creall
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index a57efbb8e464d..491e6df66162c 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -444,6 +444,8 @@ endif()
set(TARGET_LIBM_ENTRYPOINTS
# complex.h entrypoints
+ libc.src.complex.carg
+ libc.src.complex.cargf
libc.src.complex.creal
libc.src.complex.crealf
libc.src.complex.creall
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index ce88a6749d9dc..1ca5fab6da216 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -510,6 +510,8 @@ endif()
set(TARGET_LIBM_ENTRYPOINTS
# complex.h entrypoints
+ libc.src.complex.carg
+ libc.src.complex.cargf
libc.src.complex.creal
libc.src.complex.crealf
libc.src.complex.creall
diff --git a/libc/include/complex.yaml b/libc/include/complex.yaml
index 4db42be6082da..29799799d2e6b 100644
--- a/libc/include/complex.yaml
+++ b/libc/include/complex.yaml
@@ -21,6 +21,18 @@ types:
enums: []
objects: []
functions:
+ - name: carg
+ standards:
+ - stdc
+ return_type: double
+ arguments:
+ - type: _Complex double
+ - name: cargf
+ standards:
+ - stdc
+ return_type: float
+ arguments:
+ - type: _Complex float
- name: cimag
standards:
- stdc
diff --git a/libc/src/complex/CMakeLists.txt b/libc/src/complex/CMakeLists.txt
index bc66a5445d727..1ebc1e8ac6141 100644
--- a/libc/src/complex/CMakeLists.txt
+++ b/libc/src/complex/CMakeLists.txt
@@ -36,3 +36,7 @@ add_complex_entrypoint_object(cprojf)
add_complex_entrypoint_object(cprojl)
add_complex_entrypoint_object(cprojf16)
add_complex_entrypoint_object(cprojf128)
+
+add_complex_entrypoint_object(carg)
+add_complex_entrypoint_object(cargf)
+
diff --git a/libc/src/complex/carg.h b/libc/src/complex/carg.h
new file mode 100644
index 0000000000000..3dfaf592d38ce
--- /dev/null
+++ b/libc/src/complex/carg.h
@@ -0,0 +1,20 @@
+//===-- Implementation header for carg --------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_COMPLEX_CARG_H
+#define LLVM_LIBC_SRC_COMPLEX_CARG_H
+
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+double carg(_Complex double x);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_COMPLEX_CARG_H
diff --git a/libc/src/complex/cargf.h b/libc/src/complex/cargf.h
new file mode 100644
index 0000000000000..24d3cc0684fc8
--- /dev/null
+++ b/libc/src/complex/cargf.h
@@ -0,0 +1,20 @@
+//===-- Implementation header for cargf -------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_COMPLEX_CARGF_H
+#define LLVM_LIBC_SRC_COMPLEX_CARGF_H
+
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+float cargf(_Complex float x);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_COMPLEX_CARGF_H
diff --git a/libc/src/complex/generic/CMakeLists.txt b/libc/src/complex/generic/CMakeLists.txt
index f1c21e4ed7271..f9e149c9c0230 100644
--- a/libc/src/complex/generic/CMakeLists.txt
+++ b/libc/src/complex/generic/CMakeLists.txt
@@ -1,3 +1,28 @@
+add_entrypoint_object(
+ carg
+ SRCS
+ carg.cpp
+ HDRS
+ ../carg.h
+ DEPENDS
+ libc.src.__support.CPP.bit
+ libc.src.__support.complex_type
+ libc.src.__support.math.atan2
+)
+
+add_entrypoint_object(
+ cargf
+ SRCS
+ cargf.cpp
+ HDRS
+ ../cargf.h
+ DEPENDS
+ libc.src.__support.CPP.bit
+ libc.src.__support.complex_type
+ libc.src.__support.math.atan2f
+)
+
+
add_entrypoint_object(
cproj
SRCS
diff --git a/libc/src/complex/generic/carg.cpp b/libc/src/complex/generic/carg.cpp
new file mode 100644
index 0000000000000..c0f731d55da1e
--- /dev/null
+++ b/libc/src/complex/generic/carg.cpp
@@ -0,0 +1,22 @@
+//===-- Implementation of carg function -----------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/complex/carg.h"
+#include "src/__support/CPP/bit.h"
+#include "src/__support/common.h"
+#include "src/__support/complex_type.h"
+#include "src/__support/math/atan2.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(double, carg, (_Complex double x)) {
+ Complex<double> x_c = cpp::bit_cast<Complex<double>>(x);
+ return math::atan2(x_c.imag, x_c.real);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/complex/generic/cargf.cpp b/libc/src/complex/generic/cargf.cpp
new file mode 100644
index 0000000000000..7497192d8a147
--- /dev/null
+++ b/libc/src/complex/generic/cargf.cpp
@@ -0,0 +1,22 @@
+//===-- Implementation of cargf function ----------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/complex/cargf.h"
+#include "src/__support/CPP/bit.h"
+#include "src/__support/common.h"
+#include "src/__support/complex_type.h"
+#include "src/__support/math/atan2f.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(float, cargf, (_Complex float x)) {
+ Complex<float> x_c = cpp::bit_cast<Complex<float>>(x);
+ return math::atan2f(x_c.imag, x_c.real);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/src/complex/CArgTest.h b/libc/test/src/complex/CArgTest.h
new file mode 100644
index 0000000000000..890b3f280d9dc
--- /dev/null
+++ b/libc/test/src/complex/CArgTest.h
@@ -0,0 +1,102 @@
+//===-- Utility class to test different flavors of carg ---------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_TEST_SRC_COMPLEX_CARGTEST_H
+#define LLVM_LIBC_TEST_SRC_COMPLEX_CARGTEST_H
+
+#include "test/UnitTest/FEnvSafeTest.h"
+#include "test/UnitTest/FPMatcher.h"
+#include "test/UnitTest/Test.h"
+
+#include "hdr/math_macros.h"
+
+template <typename CFPT, typename FPT>
+class CArgTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
+
+ DECLARE_SPECIAL_CONSTANTS(FPT)
+
+public:
+ typedef FPT (*CArgFunc)(CFPT);
+
+ void testZeroValues(CArgFunc func) {
+ EXPECT_FP_EQ(func(CFPT{0.0, 0.0}), zero);
+ EXPECT_FP_EQ(func(CFPT{0.0, -0.0}), neg_zero);
+ EXPECT_FP_EQ(func(CFPT{1.0, 0.0}), zero);
+ EXPECT_FP_EQ(func(CFPT{128.0, 0.0}), zero);
+ EXPECT_FP_EQ(func(CFPT{1.0, -0.0}), neg_zero);
+ }
+
+ void testInfinityValues(CArgFunc func) {
+ // carg(+inf + yi) = +0 for finite y > 0
+ EXPECT_FP_EQ(zero, func(CFPT{inf, 1.0}));
+ EXPECT_FP_EQ(zero, func(CFPT{inf, 256.0}));
+ // carg(+inf - yi) = -0 for finite y > 0
+ EXPECT_FP_EQ(neg_zero, func(CFPT{inf, -1.0}));
+ EXPECT_FP_EQ(neg_zero, func(CFPT{inf, -1024.0}));
+ // carg(+inf + 0i) = +0
+ EXPECT_FP_EQ(zero, func(CFPT{inf, 0.0}));
+ // carg(+inf - 0i) = -0
+ EXPECT_FP_EQ(neg_zero, func(CFPT{inf, -0.0}));
+
+ // carg(-inf + yi) = +pi for finite y > 0
+ EXPECT_FP_EQ(FPT(M_PI), func(CFPT{neg_inf, 1.0}));
+ EXPECT_FP_EQ(FPT(M_PI), func(CFPT{neg_inf, 64.0}));
+ // carg(-inf - yi) = -pi for finite y > 0
+ EXPECT_FP_EQ(FPT(-M_PI), func(CFPT{neg_inf,-1.0}));
+ EXPECT_FP_EQ(FPT(-M_PI), func(CFPT{neg_inf, -512.0}));
+ // carg(-inf + 0i) = +pi
+ EXPECT_FP_EQ(FPT(M_PI), func(CFPT{neg_inf, 0.0}));
+ // carg(-inf - 0i) = -pi
+ EXPECT_FP_EQ(FPT(-M_PI), func(CFPT{neg_inf, -0.0}));
+
+ // carg(x + inf*i) = +pi/2 for finite x
+ EXPECT_FP_EQ(FPT(M_PI_2), func(CFPT{1.0, inf}));
+ EXPECT_FP_EQ(FPT(M_PI_2), func(CFPT{-1.0, inf}));
+ EXPECT_FP_EQ(FPT(M_PI_2), func(CFPT{0.0, inf}));
+ EXPECT_FP_EQ(FPT(M_PI_2), func(CFPT{4.0, inf}));
+ // carg(x - inf*i) = -pi/2 for finite x
+ EXPECT_FP_EQ(FPT(-M_PI_2), func(CFPT{1.0, neg_inf}));
+ EXPECT_FP_EQ(FPT(-M_PI_2), func(CFPT{-1.0, neg_inf}));
+ EXPECT_FP_EQ(FPT(-M_PI_2), func(CFPT{0.0, neg_inf}));
+ EXPECT_FP_EQ(FPT(-M_PI_2), func(CFPT{4.0, neg_inf}));
+ }
+
+ void testNaNValues(CArgFunc func) {
+ // carg(NaN + yi) = NaN for finite y
+ EXPECT_FP_IS_NAN(func(CFPT{aNaN, 0.0}));
+ EXPECT_FP_IS_NAN(func(CFPT{aNaN, 1.0}));
+ EXPECT_FP_IS_NAN(func(CFPT{aNaN, -1.0}));
+ EXPECT_FP_IS_NAN(func(CFPT{aNaN, 512.0}));
+
+ // carg(x + NaN*i) = NaN for finite x
+ EXPECT_FP_IS_NAN(func(CFPT{0.0, aNaN}));
+ EXPECT_FP_IS_NAN(func(CFPT{1.0, aNaN}));
+ EXPECT_FP_IS_NAN(func(CFPT{-1.0, aNaN}));
+ EXPECT_FP_IS_NAN(func(CFPT{4.0, aNaN}));
+
+ // carg(NaN + NaN*i) = NaN
+ EXPECT_FP_IS_NAN(func(CFPT{aNaN, aNaN}));
+
+ // carg(+inf + NaN*i) = NaN
+ EXPECT_FP_IS_NAN(func(CFPT{inf, aNaN}));
+ // carg(-inf + NaN*i) = NaN
+ EXPECT_FP_IS_NAN(func(CFPT{neg_inf, aNaN}));
+ // carg(NaN + inf*i) = NaN
+ EXPECT_FP_IS_NAN(func(CFPT{aNaN, inf}));
+ // carg(NaN - inf*i) = NaN
+ EXPECT_FP_IS_NAN(func(CFPT{aNaN, neg_inf}));
+ }
+};
+
+#define LIST_CARG_TESTS(U, T, func) \
+ using LlvmLibcCArgTest = CArgTest<U, T>; \
+ TEST_F(LlvmLibcCArgTest, ZeroValues) { testZeroValues(&func); } \
+ TEST_F(LlvmLibcCArgTest, InfinityValues) { testInfinityValues(&func); } \
+ TEST_F(LlvmLibcCArgTest, NaNValues) { testNaNValues(&func); }
+
+#endif // LLVM_LIBC_TEST_SRC_COMPLEX_CARGTEST_H
diff --git a/libc/test/src/complex/CMakeLists.txt b/libc/test/src/complex/CMakeLists.txt
index efd1ede63eca5..fda44fa2f1422 100644
--- a/libc/test/src/complex/CMakeLists.txt
+++ b/libc/test/src/complex/CMakeLists.txt
@@ -1,5 +1,25 @@
add_custom_target(libc-complex-unittests)
+add_fp_unittest(
+ carg_test
+ SUITE
+ libc-complex-unittests
+ SRCS
+ carg_test.cpp
+ DEPENDS
+ libc.src.complex.carg
+)
+
+add_fp_unittest(
+ cargf_test
+ SUITE
+ libc-complex-unittests
+ SRCS
+ cargf_test.cpp
+ DEPENDS
+ libc.src.complex.cargf
+)
+
add_fp_unittest(
conj_test
SUITE
diff --git a/libc/test/src/complex/carg_test.cpp b/libc/test/src/complex/carg_test.cpp
new file mode 100644
index 0000000000000..f6fd1d7df5e31
--- /dev/null
+++ b/libc/test/src/complex/carg_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for carg -------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "CArgTest.h"
+
+#include "src/complex/carg.h"
+
+LIST_CARG_TESTS(_Complex double, double, LIBC_NAMESPACE::carg)
diff --git a/libc/test/src/complex/cargf_test.cpp b/libc/test/src/complex/cargf_test.cpp
new file mode 100644
index 0000000000000..1c47be9c644ae
--- /dev/null
+++ b/libc/test/src/complex/cargf_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for cargf ------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "CArgTest.h"
+
+#include "src/complex/cargf.h"
+
+LIST_CARG_TESTS(_Complex float, float, LIBC_NAMESPACE::cargf)
>From 4b5d1365f250c0a315debb382601df074da8cec5 Mon Sep 17 00:00:00 2001
From: jinge90 <ge.jin at intel.com>
Date: Tue, 16 Jun 2026 16:50:19 +0800
Subject: [PATCH 2/6] remove arm riscv aarch64
Signed-off-by: jinge90 <ge.jin at intel.com>
---
libc/config/linux/aarch64/entrypoints.txt | 2 --
libc/config/linux/arm/entrypoints.txt | 2 --
libc/config/linux/riscv/entrypoints.txt | 2 --
3 files changed, 6 deletions(-)
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index a5785620bb4c2..5cddf3dc89799 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -440,8 +440,6 @@ endif()
set(TARGET_LIBM_ENTRYPOINTS
# complex.h entrypoints
- libc.src.complex.carg
- libc.src.complex.cargf
libc.src.complex.creal
libc.src.complex.crealf
libc.src.complex.creall
diff --git a/libc/config/linux/arm/entrypoints.txt b/libc/config/linux/arm/entrypoints.txt
index d2a75f0e1c739..c4ac53c4925a3 100644
--- a/libc/config/linux/arm/entrypoints.txt
+++ b/libc/config/linux/arm/entrypoints.txt
@@ -236,8 +236,6 @@ endif()
set(TARGET_LIBM_ENTRYPOINTS
# complex.h entrypoints
- libc.src.complex.carg
- libc.src.complex.cargf
libc.src.complex.creal
libc.src.complex.crealf
libc.src.complex.creall
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index 491e6df66162c..a57efbb8e464d 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -444,8 +444,6 @@ endif()
set(TARGET_LIBM_ENTRYPOINTS
# complex.h entrypoints
- libc.src.complex.carg
- libc.src.complex.cargf
libc.src.complex.creal
libc.src.complex.crealf
libc.src.complex.creall
>From 8ee717a4d7109b0860f17f78c42bef45b97a1d68 Mon Sep 17 00:00:00 2001
From: jinge90 <ge.jin at intel.com>
Date: Tue, 16 Jun 2026 16:53:55 +0800
Subject: [PATCH 3/6] Fix clang format
Signed-off-by: jinge90 <ge.jin at intel.com>
---
libc/test/src/complex/CArgTest.h | 2 +-
libc/test/src/complex/carg_test.cpp | 2 +-
libc/test/src/complex/cargf_test.cpp | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/libc/test/src/complex/CArgTest.h b/libc/test/src/complex/CArgTest.h
index 890b3f280d9dc..9a8d87e1d20e8 100644
--- a/libc/test/src/complex/CArgTest.h
+++ b/libc/test/src/complex/CArgTest.h
@@ -47,7 +47,7 @@ class CArgTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
EXPECT_FP_EQ(FPT(M_PI), func(CFPT{neg_inf, 1.0}));
EXPECT_FP_EQ(FPT(M_PI), func(CFPT{neg_inf, 64.0}));
// carg(-inf - yi) = -pi for finite y > 0
- EXPECT_FP_EQ(FPT(-M_PI), func(CFPT{neg_inf,-1.0}));
+ EXPECT_FP_EQ(FPT(-M_PI), func(CFPT{neg_inf, -1.0}));
EXPECT_FP_EQ(FPT(-M_PI), func(CFPT{neg_inf, -512.0}));
// carg(-inf + 0i) = +pi
EXPECT_FP_EQ(FPT(M_PI), func(CFPT{neg_inf, 0.0}));
diff --git a/libc/test/src/complex/carg_test.cpp b/libc/test/src/complex/carg_test.cpp
index f6fd1d7df5e31..c9f8537912ac4 100644
--- a/libc/test/src/complex/carg_test.cpp
+++ b/libc/test/src/complex/carg_test.cpp
@@ -1,4 +1,4 @@
-//===-- Unittests for carg -------------------------------------------------===//
+//===-- Unittests for carg ------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
diff --git a/libc/test/src/complex/cargf_test.cpp b/libc/test/src/complex/cargf_test.cpp
index 1c47be9c644ae..f9cd49db4937c 100644
--- a/libc/test/src/complex/cargf_test.cpp
+++ b/libc/test/src/complex/cargf_test.cpp
@@ -1,4 +1,4 @@
-//===-- Unittests for cargf ------------------------------------------------===//
+//===-- Unittests for cargf -----------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
>From 3fd7bf27637fa7d38680b2fb85a1b224fa89a6e8 Mon Sep 17 00:00:00 2001
From: jinge90 <ge.jin at intel.com>
Date: Thu, 18 Jun 2026 11:38:16 +0800
Subject: [PATCH 4/6] add carg, cargf to other targets
Signed-off-by: jinge90 <ge.jin at intel.com>
---
libc/config/baremetal/aarch64/entrypoints.txt | 2 ++
libc/config/baremetal/arm/entrypoints.txt | 2 ++
libc/config/baremetal/riscv/entrypoints.txt | 2 ++
libc/config/darwin/aarch64/entrypoints.txt | 2 ++
libc/config/linux/aarch64/entrypoints.txt | 2 ++
libc/config/linux/arm/entrypoints.txt | 2 ++
libc/config/linux/riscv/entrypoints.txt | 2 ++
7 files changed, 14 insertions(+)
diff --git a/libc/config/baremetal/aarch64/entrypoints.txt b/libc/config/baremetal/aarch64/entrypoints.txt
index ed419b1de5ea5..f64eb55b40acd 100644
--- a/libc/config/baremetal/aarch64/entrypoints.txt
+++ b/libc/config/baremetal/aarch64/entrypoints.txt
@@ -311,6 +311,8 @@ set(TARGET_LIBC_ENTRYPOINTS
set(TARGET_LIBM_ENTRYPOINTS
# complex.h entrypoints
+ libc.src.complex.carg
+ libc.src.complex.cargf
libc.src.complex.creal
libc.src.complex.crealf
libc.src.complex.creall
diff --git a/libc/config/baremetal/arm/entrypoints.txt b/libc/config/baremetal/arm/entrypoints.txt
index 2dde53d2374a5..55a175923faa1 100644
--- a/libc/config/baremetal/arm/entrypoints.txt
+++ b/libc/config/baremetal/arm/entrypoints.txt
@@ -323,6 +323,8 @@ set(TARGET_LIBC_ENTRYPOINTS
set(TARGET_LIBM_ENTRYPOINTS
# complex.h entrypoints
+ libc.src.complex.carg
+ libc.src.complex.cargf
libc.src.complex.creal
libc.src.complex.crealf
libc.src.complex.creall
diff --git a/libc/config/baremetal/riscv/entrypoints.txt b/libc/config/baremetal/riscv/entrypoints.txt
index 948b870e37987..96be24e6343d4 100644
--- a/libc/config/baremetal/riscv/entrypoints.txt
+++ b/libc/config/baremetal/riscv/entrypoints.txt
@@ -321,6 +321,8 @@ set(TARGET_LIBC_ENTRYPOINTS
set(TARGET_LIBM_ENTRYPOINTS
# complex.h entrypoints
+ libc.src.complex.carg
+ libc.src.complex.cargf
libc.src.complex.creal
libc.src.complex.crealf
libc.src.complex.creall
diff --git a/libc/config/darwin/aarch64/entrypoints.txt b/libc/config/darwin/aarch64/entrypoints.txt
index 894d90143d09f..413534a14f34e 100644
--- a/libc/config/darwin/aarch64/entrypoints.txt
+++ b/libc/config/darwin/aarch64/entrypoints.txt
@@ -132,6 +132,8 @@ endif()
set(TARGET_LIBM_ENTRYPOINTS
# complex.h entrypoints
+ libc.src.complex.carg
+ libc.src.complex.cargf
libc.src.complex.creal
libc.src.complex.crealf
libc.src.complex.creall
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index 5cddf3dc89799..a5785620bb4c2 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -440,6 +440,8 @@ endif()
set(TARGET_LIBM_ENTRYPOINTS
# complex.h entrypoints
+ libc.src.complex.carg
+ libc.src.complex.cargf
libc.src.complex.creal
libc.src.complex.crealf
libc.src.complex.creall
diff --git a/libc/config/linux/arm/entrypoints.txt b/libc/config/linux/arm/entrypoints.txt
index c4ac53c4925a3..d2a75f0e1c739 100644
--- a/libc/config/linux/arm/entrypoints.txt
+++ b/libc/config/linux/arm/entrypoints.txt
@@ -236,6 +236,8 @@ endif()
set(TARGET_LIBM_ENTRYPOINTS
# complex.h entrypoints
+ libc.src.complex.carg
+ libc.src.complex.cargf
libc.src.complex.creal
libc.src.complex.crealf
libc.src.complex.creall
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index a57efbb8e464d..491e6df66162c 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -444,6 +444,8 @@ endif()
set(TARGET_LIBM_ENTRYPOINTS
# complex.h entrypoints
+ libc.src.complex.carg
+ libc.src.complex.cargf
libc.src.complex.creal
libc.src.complex.crealf
libc.src.complex.creall
>From 656e6a3886c2fd7ed847df57f81538ebcb7ecf9d Mon Sep 17 00:00:00 2001
From: jinge90 <ge.jin at intel.com>
Date: Thu, 18 Jun 2026 15:37:47 +0800
Subject: [PATCH 5/6] Add basic tests for normal inputs
Signed-off-by: jinge90 <ge.jin at intel.com>
---
libc/test/src/complex/CMakeLists.txt | 2 ++
libc/test/src/complex/carg_test.cpp | 18 ++++++++++++++++++
libc/test/src/complex/cargf_test.cpp | 19 +++++++++++++++++++
3 files changed, 39 insertions(+)
diff --git a/libc/test/src/complex/CMakeLists.txt b/libc/test/src/complex/CMakeLists.txt
index fda44fa2f1422..7cfcdf0641773 100644
--- a/libc/test/src/complex/CMakeLists.txt
+++ b/libc/test/src/complex/CMakeLists.txt
@@ -2,6 +2,7 @@ add_custom_target(libc-complex-unittests)
add_fp_unittest(
carg_test
+ NEED_MPC
SUITE
libc-complex-unittests
SRCS
@@ -12,6 +13,7 @@ add_fp_unittest(
add_fp_unittest(
cargf_test
+ NEED_MPC
SUITE
libc-complex-unittests
SRCS
diff --git a/libc/test/src/complex/carg_test.cpp b/libc/test/src/complex/carg_test.cpp
index c9f8537912ac4..4b20189cb1871 100644
--- a/libc/test/src/complex/carg_test.cpp
+++ b/libc/test/src/complex/carg_test.cpp
@@ -9,5 +9,23 @@
#include "CArgTest.h"
#include "src/complex/carg.h"
+#include "utils/MPCWrapper/MPCUtils.h"
+
+using LlvmLibcCargMPCTest = LIBC_NAMESPACE::testing::FPTest<double>;
+
+namespace mpc = LIBC_NAMESPACE::testing::mpc;
+
+TEST_F(LlvmLibcCargMPCTest, BasicForRounding) {
+ _Complex double test_values[] = {
+ 1.0 + 1.0i, -1.0 + 1.0i, 1.0 - 1.0i, -1.0 - 1.0i, 3.0 + 4.0i,
+ -3.0 + 4.0i, 3.0 - 4.0i, -3.0 - 4.0i, 0.5 + 0.5i, -0.5 + 0.5i,
+ 0.5 - 0.5i, -0.5 - 0.5i, 1.0 + 0.0i, -1.0 + 0.0i, 0.0 + 1.0i,
+ 0.0 - 1.0i, 5.0 + 12.0i, 100.0 + 1.0i, 0.001 + 1000.0i,
+ };
+ for (_Complex double val : test_values) {
+ EXPECT_MPC_MATCH_ALL_ROUNDING(mpc::Operation::Carg, val,
+ LIBC_NAMESPACE::carg(val), 0.5);
+ }
+}
LIST_CARG_TESTS(_Complex double, double, LIBC_NAMESPACE::carg)
diff --git a/libc/test/src/complex/cargf_test.cpp b/libc/test/src/complex/cargf_test.cpp
index f9cd49db4937c..727247ab31b61 100644
--- a/libc/test/src/complex/cargf_test.cpp
+++ b/libc/test/src/complex/cargf_test.cpp
@@ -9,5 +9,24 @@
#include "CArgTest.h"
#include "src/complex/cargf.h"
+#include "utils/MPCWrapper/MPCUtils.h"
+
+using LlvmLibcCargfMPCTest = LIBC_NAMESPACE::testing::FPTest<float>;
+
+namespace mpc = LIBC_NAMESPACE::testing::mpc;
+
+TEST_F(LlvmLibcCargfMPCTest, BasicForRounding) {
+ _Complex float test_values[] = {
+ 1.0f + 1.0fi, -1.0f + 1.0fi, 1.0f - 1.0fi, -1.0f - 1.0fi,
+ 3.0f + 4.0fi, -3.0f + 4.0fi, 3.0f - 4.0fi, -3.0f - 4.0fi,
+ 0.5f + 0.5fi, -0.5f + 0.5fi, 0.5f - 0.5fi, -0.5f - 0.5fi,
+ 1.0f + 0.0fi, -1.0f + 0.0fi, 0.0f + 1.0fi, 0.0f - 1.0fi,
+ 5.0f + 12.0fi, 100.0f + 1.0fi, 0.001f + 1000.0fi,
+ };
+ for (_Complex float val : test_values) {
+ EXPECT_MPC_MATCH_ALL_ROUNDING(mpc::Operation::Carg, val,
+ LIBC_NAMESPACE::cargf(val), 0.5);
+ }
+}
LIST_CARG_TESTS(_Complex float, float, LIBC_NAMESPACE::cargf)
>From 2291271d954079894c9b5cae3554a49caa190300 Mon Sep 17 00:00:00 2001
From: jinge90 <ge.jin at intel.com>
Date: Mon, 22 Jun 2026 11:31:47 +0800
Subject: [PATCH 6/6] update status page
Signed-off-by: jinge90 <ge.jin at intel.com>
---
libc/docs/headers/complex.rst | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libc/docs/headers/complex.rst b/libc/docs/headers/complex.rst
index ba7d73eb499ac..1a0137d6dea51 100644
--- a/libc/docs/headers/complex.rst
+++ b/libc/docs/headers/complex.rst
@@ -51,7 +51,7 @@ Functions
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| csqrt | | | | | | 7.3.8.3 | G.6.5.2 |
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
-| carg | | | | | | 7.3.9.1 | N/A |
+| carg | |check| | 1 ULP | | | | 7.3.9.1 | N/A |
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| cimag | |check| | |check| | |check| | |check| | |check| | 7.3.9.2 | N/A |
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
More information about the libc-commits
mailing list