[libc-commits] [libc] [libc][complex] Set up headers and add documentation (PR #111659)

Shourya Goel via libc-commits libc-commits at lists.llvm.org
Thu Oct 10 10:59:25 PDT 2024


https://github.com/Sh0g0-1758 updated https://github.com/llvm/llvm-project/pull/111659

>From d9c3226ef2db2a2a9e63e93f79a6dacc65a9691f Mon Sep 17 00:00:00 2001
From: Sh0g0-1758 <shouryagoel10000 at gmail.com>
Date: Tue, 8 Oct 2024 00:29:47 +0530
Subject: [PATCH 01/11] init

---
 .../include/llvm-libc-macros/complex-macros.h | 21 +++++++++++++++++++
 1 file changed, 21 insertions(+)
 create mode 100644 libc/include/llvm-libc-macros/complex-macros.h

diff --git a/libc/include/llvm-libc-macros/complex-macros.h b/libc/include/llvm-libc-macros/complex-macros.h
new file mode 100644
index 00000000000000..175ada6594e3b9
--- /dev/null
+++ b/libc/include/llvm-libc-macros/complex-macros.h
@@ -0,0 +1,21 @@
+//===-- Definition of macros to be used with complex functions ------------===//
+//
+// 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_MACROS_COMPLEX_MACROS_H
+#define __LLVM_LIBC_MACROS_COMPLEX_MACROS_H
+
+#ifndef __STDC_NO_COMPLEX__
+
+#define __STDC_VERSION_COMPLEX_H__ 202311L
+
+#define complex _Complex
+#define _Complex_I 1.0fi
+
+#endif
+
+#endif // __LLVM_LIBC_MACROS_COMPLEX_MACROS_H

>From 135b2ebc781d4c2ad613c51e0c17486732ef7681 Mon Sep 17 00:00:00 2001
From: Sh0g0-1758 <shouryagoel10000 at gmail.com>
Date: Wed, 9 Oct 2024 16:01:02 +0530
Subject: [PATCH 02/11] Libc: Complex init

---
 libc/docs/complex.rst                         | 65 +++++++++++++++++++
 libc/include/CMakeLists.txt                   | 10 +++
 libc/include/complex.h.def                    | 17 +++++
 libc/include/llvm-libc-macros/CMakeLists.txt  |  6 ++
 .../include/llvm-libc-macros/complex-macros.h | 11 +++-
 5 files changed, 108 insertions(+), 1 deletion(-)
 create mode 100644 libc/docs/complex.rst
 create mode 100644 libc/include/complex.h.def

diff --git a/libc/docs/complex.rst b/libc/docs/complex.rst
new file mode 100644
index 00000000000000..f56910067ef9a2
--- /dev/null
+++ b/libc/docs/complex.rst
@@ -0,0 +1,65 @@
+.. include:: check.rst
+
+=========
+complex.h
+=========
+
+Macros
+======
+
++-----------+------------------+-----------------+------------------------+------------------------+----------------------------+
+| <Func>    | <Func_f> (float) | <Func> (double) | <Func_l> (long double) | C23 Definition Section | C23 Error Handling Section |
++===========+==================+=================+========================+========================+============================+
+| CMPLX     |                  |                 |                        | 7.3.9.3                | N/A                        |
++-----------+------------------+-----------------+------------------------+------------------------+----------------------------+
+
+Functions
+=========
+
++-----------+------------------+-----------------+------------------------+------------------------+----------------------------+
+| <Func>    | <Func_f> (float) | <Func> (double) | <Func_l> (long double) | C23 Definition Section | C23 Error Handling Section |
++===========+==================+=================+========================+========================+============================+
+| cacos     |                  |                 |                        | 7.3.5.1                | G.6.2.1                    |
++-----------+------------------+-----------------+------------------------+------------------------+----------------------------+
+| casin     |                  |                 |                        | 7.3.5.2                | N/A                        |
++-----------+------------------+-----------------+------------------------+------------------------+----------------------------+
+| catan     |                  |                 |                        | 7.3.5.3                | N/A                        |
++-----------+------------------+-----------------+------------------------+------------------------+----------------------------+
+| ccos      |                  |                 |                        | 7.3.5.4                | N/A                        |
++-----------+------------------+-----------------+------------------------+------------------------+----------------------------+
+| csin      |                  |                 |                        | 7.3.5.5                | N/A                        |
++-----------+------------------+-----------------+------------------------+------------------------+----------------------------+
+| ctan      |                  |                 |                        | 7.3.5.6                | N/A                        |
++-----------+------------------+-----------------+------------------------+------------------------+----------------------------+
+| cacosh    |                  |                 |                        | 7.3.6.1                | G.6.3.1                    |
++-----------+------------------+-----------------+------------------------+------------------------+----------------------------+
+| casinh    |                  |                 |                        | 7.3.6.2                | G.6.3.2                    |
++-----------+------------------+-----------------+------------------------+------------------------+----------------------------+
+| catanh    |                  |                 |                        | 7.3.6.3                | G.6.3.3                    |
++-----------+------------------+-----------------+------------------------+------------------------+----------------------------+
+| ccosh     |                  |                 |                        | 7.3.6.4                | G.6.3.4                    |
++-----------+------------------+-----------------+------------------------+------------------------+----------------------------+
+| csinh     |                  |                 |                        | 7.3.6.5                | G.6.3.5                    |
++-----------+------------------+-----------------+------------------------+------------------------+----------------------------+
+| ctanh     |                  |                 |                        | 7.3.6.6                | G.6.3.6                    |
++-----------+------------------+-----------------+------------------------+------------------------+----------------------------+
+| cexp      |                  |                 |                        | 7.3.7.1                | G.6.4.1                    |
++-----------+------------------+-----------------+------------------------+------------------------+----------------------------+
+| clog      |                  |                 |                        | 7.3.7.2                | G.6.4.2                    |
++-----------+------------------+-----------------+------------------------+------------------------+----------------------------+
+| cabs      |                  |                 |                        | 7.3.8.1                | N/A                        |
++-----------+------------------+-----------------+------------------------+------------------------+----------------------------+
+| cpow      |                  |                 |                        | 7.3.8.2                | G.6.5.1                    |
++-----------+------------------+-----------------+------------------------+------------------------+----------------------------+
+| csqrt     |                  |                 |                        | 7.3.8.3                | G.6.5.2                    |
++-----------+------------------+-----------------+------------------------+------------------------+----------------------------+
+| carg      |                  |                 |                        | 7.3.9.1                | N/A                        |
++-----------+------------------+-----------------+------------------------+------------------------+----------------------------+
+| cimag     |                  |                 |                        | 7.3.9.2                | N/A                        |
++-----------+------------------+-----------------+------------------------+------------------------+----------------------------+
+| conj      |                  |                 |                        | 7.3.9.4                | N/A                        |
++-----------+------------------+-----------------+------------------------+------------------------+----------------------------+
+| cproj     |                  |                 |                        | 7.3.9.5                | N/A                        |
++-----------+------------------+-----------------+------------------------+------------------------+----------------------------+
+| creal     |                  |                 |                        | 7.3.9.6                | N/A                        |
++-----------+------------------+-----------------+------------------------+------------------------+----------------------------+
diff --git a/libc/include/CMakeLists.txt b/libc/include/CMakeLists.txt
index 1f3cb59f69e96e..5deb5258d532fe 100644
--- a/libc/include/CMakeLists.txt
+++ b/libc/include/CMakeLists.txt
@@ -202,6 +202,16 @@ add_header_macro(
     .llvm-libc-macros.assert_macros
 )
 
+add_header_macro(
+  complex
+  ../libc/newhdrgen/yaml/complex.yaml
+  complex.h.def
+  complex.h
+  DEPENDS
+    .llvm_libc_common_h
+    .llvm-libc-macros.complex_macros
+)
+
 add_header_macro(
   setjmp
   ../libc/newhdrgen/yaml/setjmp.yaml
diff --git a/libc/include/complex.h.def b/libc/include/complex.h.def
new file mode 100644
index 00000000000000..65f5765573e840
--- /dev/null
+++ b/libc/include/complex.h.def
@@ -0,0 +1,17 @@
+//===-- C standard library header complex.h -------------------------------===//
+//
+// 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_COMPLEX_H
+#define LLVM_LIBC_COMPLEX_H
+
+#include "__llvm-libc-common.h"
+#include "llvm-libc-macros/complex-macros.h"
+
+%%public_api()
+
+#endif // LLVM_LIBC_COMPLEX_H
diff --git a/libc/include/llvm-libc-macros/CMakeLists.txt b/libc/include/llvm-libc-macros/CMakeLists.txt
index 2ba437c8437f28..75194923a452fb 100644
--- a/libc/include/llvm-libc-macros/CMakeLists.txt
+++ b/libc/include/llvm-libc-macros/CMakeLists.txt
@@ -61,6 +61,12 @@ add_macro_header(
     fcntl-macros.h
 )
 
+add_macro_header(
+  complex_macros
+  HDR
+    complex-macros.h
+)
+
 add_macro_header(
   features_macros
   HDR
diff --git a/libc/include/llvm-libc-macros/complex-macros.h b/libc/include/llvm-libc-macros/complex-macros.h
index 175ada6594e3b9..3c239a04f8a6ad 100644
--- a/libc/include/llvm-libc-macros/complex-macros.h
+++ b/libc/include/llvm-libc-macros/complex-macros.h
@@ -14,7 +14,16 @@
 #define __STDC_VERSION_COMPLEX_H__ 202311L
 
 #define complex _Complex
-#define _Complex_I 1.0fi
+#define _Complex_I (float _Complex)1.0fi
+
+#ifdef _Imaginary
+#define imaginary _Imaginary
+#define _Imaginary_I (float _Imaginary)1.0i
+
+#define I _Imaginary_I
+#else
+#define I _Complex_I
+#endif
 
 #endif
 

>From 4fc0e05d871ecf2021e299fe9bfbef153067832f Mon Sep 17 00:00:00 2001
From: Sh0g0-1758 <shouryagoel10000 at gmail.com>
Date: Wed, 9 Oct 2024 16:36:49 +0530
Subject: [PATCH 03/11] add _Imaginary type

---
 libc/include/CMakeLists.txt                 |  1 +
 libc/include/llvm-libc-types/CMakeLists.txt |  1 +
 libc/include/llvm-libc-types/_Imaginary.h   | 14 ++++++++++++++
 3 files changed, 16 insertions(+)
 create mode 100644 libc/include/llvm-libc-types/_Imaginary.h

diff --git a/libc/include/CMakeLists.txt b/libc/include/CMakeLists.txt
index 5deb5258d532fe..9a07445ec8b5b6 100644
--- a/libc/include/CMakeLists.txt
+++ b/libc/include/CMakeLists.txt
@@ -210,6 +210,7 @@ add_header_macro(
   DEPENDS
     .llvm_libc_common_h
     .llvm-libc-macros.complex_macros
+    .llvm-libc-types._Imaginary
 )
 
 add_header_macro(
diff --git a/libc/include/llvm-libc-types/CMakeLists.txt b/libc/include/llvm-libc-types/CMakeLists.txt
index a4cf4631c8470e..f0dadc99099c7d 100644
--- a/libc/include/llvm-libc-types/CMakeLists.txt
+++ b/libc/include/llvm-libc-types/CMakeLists.txt
@@ -17,6 +17,7 @@ add_header(__qsortrcompare_t HDR __qsortrcompare_t.h)
 add_header(__sighandler_t HDR __sighandler_t.h)
 add_header(__thread_type HDR __thread_type.h)
 add_header(blkcnt_t HDR blkcnt_t.h)
+add_header(_Imaginary HDR _Imaginary.h)
 add_header(blksize_t HDR blksize_t.h)
 add_header(cc_t HDR cc_t.h)
 add_header(clock_t HDR clock_t.h)
diff --git a/libc/include/llvm-libc-types/_Imaginary.h b/libc/include/llvm-libc-types/_Imaginary.h
new file mode 100644
index 00000000000000..ad51bc1d37b569
--- /dev/null
+++ b/libc/include/llvm-libc-types/_Imaginary.h
@@ -0,0 +1,14 @@
+//===-- Definition of _Imaginary type -------------------------------------===//
+//
+// 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_TYPES__Imaginary_H
+#define LLVM_LIBC_TYPES__Imaginary_H
+
+typedef /* TODO */ _Imaginary;
+
+#endif // LLVM_LIBC_TYPES__Imaginary_H

>From e4e2bb4673cc935ff1136026d1f792be391bef5c Mon Sep 17 00:00:00 2001
From: Sh0g0-1758 <shouryagoel10000 at gmail.com>
Date: Wed, 9 Oct 2024 16:42:20 +0530
Subject: [PATCH 04/11] fix doc

---
 libc/docs/index.rst | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libc/docs/index.rst b/libc/docs/index.rst
index d089a800ab90ab..6f759aa215b62c 100644
--- a/libc/docs/index.rst
+++ b/libc/docs/index.rst
@@ -73,6 +73,7 @@ stages there is no ABI stability in any form.
    libc_search
    c23
    ctype
+   complex
    signal
    threads
    setjmp

>From 9021b17d020817bd09af78fc8bf31b4233016f17 Mon Sep 17 00:00:00 2001
From: Sh0g0-1758 <shouryagoel10000 at gmail.com>
Date: Thu, 10 Oct 2024 00:03:01 +0530
Subject: [PATCH 05/11] Add F16 and F128

---
 libc/docs/complex.rst | 104 +++++++++++++++++++++---------------------
 1 file changed, 52 insertions(+), 52 deletions(-)

diff --git a/libc/docs/complex.rst b/libc/docs/complex.rst
index f56910067ef9a2..09fbdd7c6179ef 100644
--- a/libc/docs/complex.rst
+++ b/libc/docs/complex.rst
@@ -7,59 +7,59 @@ complex.h
 Macros
 ======
 
-+-----------+------------------+-----------------+------------------------+------------------------+----------------------------+
-| <Func>    | <Func_f> (float) | <Func> (double) | <Func_l> (long double) | C23 Definition Section | C23 Error Handling Section |
-+===========+==================+=================+========================+========================+============================+
-| CMPLX     |                  |                 |                        | 7.3.9.3                | N/A                        |
-+-----------+------------------+-----------------+------------------------+------------------------+----------------------------+
++-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
+| <Func>    | <Func_f> (float) | <Func> (double) | <Func_l> (long double) | <Func_f16> (float16) | <Func_f128> (float128) | C23 Definition Section | C23 Error Handling Section |
++===========+==================+=================+========================+======================+========================+========================+============================+
+| CMPLX     |                  |                 |                        |                      |                        | 7.3.9.3                | N/A                        |
++-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
 
 Functions
 =========
 
-+-----------+------------------+-----------------+------------------------+------------------------+----------------------------+
-| <Func>    | <Func_f> (float) | <Func> (double) | <Func_l> (long double) | C23 Definition Section | C23 Error Handling Section |
-+===========+==================+=================+========================+========================+============================+
-| cacos     |                  |                 |                        | 7.3.5.1                | G.6.2.1                    |
-+-----------+------------------+-----------------+------------------------+------------------------+----------------------------+
-| casin     |                  |                 |                        | 7.3.5.2                | N/A                        |
-+-----------+------------------+-----------------+------------------------+------------------------+----------------------------+
-| catan     |                  |                 |                        | 7.3.5.3                | N/A                        |
-+-----------+------------------+-----------------+------------------------+------------------------+----------------------------+
-| ccos      |                  |                 |                        | 7.3.5.4                | N/A                        |
-+-----------+------------------+-----------------+------------------------+------------------------+----------------------------+
-| csin      |                  |                 |                        | 7.3.5.5                | N/A                        |
-+-----------+------------------+-----------------+------------------------+------------------------+----------------------------+
-| ctan      |                  |                 |                        | 7.3.5.6                | N/A                        |
-+-----------+------------------+-----------------+------------------------+------------------------+----------------------------+
-| cacosh    |                  |                 |                        | 7.3.6.1                | G.6.3.1                    |
-+-----------+------------------+-----------------+------------------------+------------------------+----------------------------+
-| casinh    |                  |                 |                        | 7.3.6.2                | G.6.3.2                    |
-+-----------+------------------+-----------------+------------------------+------------------------+----------------------------+
-| catanh    |                  |                 |                        | 7.3.6.3                | G.6.3.3                    |
-+-----------+------------------+-----------------+------------------------+------------------------+----------------------------+
-| ccosh     |                  |                 |                        | 7.3.6.4                | G.6.3.4                    |
-+-----------+------------------+-----------------+------------------------+------------------------+----------------------------+
-| csinh     |                  |                 |                        | 7.3.6.5                | G.6.3.5                    |
-+-----------+------------------+-----------------+------------------------+------------------------+----------------------------+
-| ctanh     |                  |                 |                        | 7.3.6.6                | G.6.3.6                    |
-+-----------+------------------+-----------------+------------------------+------------------------+----------------------------+
-| cexp      |                  |                 |                        | 7.3.7.1                | G.6.4.1                    |
-+-----------+------------------+-----------------+------------------------+------------------------+----------------------------+
-| clog      |                  |                 |                        | 7.3.7.2                | G.6.4.2                    |
-+-----------+------------------+-----------------+------------------------+------------------------+----------------------------+
-| cabs      |                  |                 |                        | 7.3.8.1                | N/A                        |
-+-----------+------------------+-----------------+------------------------+------------------------+----------------------------+
-| cpow      |                  |                 |                        | 7.3.8.2                | G.6.5.1                    |
-+-----------+------------------+-----------------+------------------------+------------------------+----------------------------+
-| csqrt     |                  |                 |                        | 7.3.8.3                | G.6.5.2                    |
-+-----------+------------------+-----------------+------------------------+------------------------+----------------------------+
-| carg      |                  |                 |                        | 7.3.9.1                | N/A                        |
-+-----------+------------------+-----------------+------------------------+------------------------+----------------------------+
-| cimag     |                  |                 |                        | 7.3.9.2                | N/A                        |
-+-----------+------------------+-----------------+------------------------+------------------------+----------------------------+
-| conj      |                  |                 |                        | 7.3.9.4                | N/A                        |
-+-----------+------------------+-----------------+------------------------+------------------------+----------------------------+
-| cproj     |                  |                 |                        | 7.3.9.5                | N/A                        |
-+-----------+------------------+-----------------+------------------------+------------------------+----------------------------+
-| creal     |                  |                 |                        | 7.3.9.6                | N/A                        |
-+-----------+------------------+-----------------+------------------------+------------------------+----------------------------+
++-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
+| <Func>    | <Func_f> (float) | <Func> (double) | <Func_l> (long double) | <Func_f16> (float16) | <Func_f128> (float128) | C23 Definition Section | C23 Error Handling Section |
++===========+==================+=================+========================+======================+========================+========================+============================+
+| cacos     |                  |                 |                        |                      |                        | 7.3.5.1                | G.6.2.1                    |
++-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
+| casin     |                  |                 |                        |                      |                        | 7.3.5.2                | N/A                        |
++-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
+| catan     |                  |                 |                        |                      |                        | 7.3.5.3                | N/A                        |
++-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
+| ccos      |                  |                 |                        |                      |                        | 7.3.5.4                | N/A                        |
++-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
+| csin      |                  |                 |                        |                      |                        | 7.3.5.5                | N/A                        |
++-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
+| ctan      |                  |                 |                        |                      |                        | 7.3.5.6                | N/A                        |
++-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
+| cacosh    |                  |                 |                        |                      |                        | 7.3.6.1                | G.6.3.1                    |
++-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
+| casinh    |                  |                 |                        |                      |                        | 7.3.6.2                | G.6.3.2                    |
++-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
+| catanh    |                  |                 |                        |                      |                        | 7.3.6.3                | G.6.3.3                    |
++-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
+| ccosh     |                  |                 |                        |                      |                        | 7.3.6.4                | G.6.3.4                    |
++-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
+| csinh     |                  |                 |                        |                      |                        | 7.3.6.5                | G.6.3.5                    |
++-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
+| ctanh     |                  |                 |                        |                      |                        | 7.3.6.6                | G.6.3.6                    |
++-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
+| cexp      |                  |                 |                        |                      |                        | 7.3.7.1                | G.6.4.1                    |
++-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
+| clog      |                  |                 |                        |                      |                        | 7.3.7.2                | G.6.4.2                    |
++-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
+| cabs      |                  |                 |                        |                      |                        | 7.3.8.1                | N/A                        |
++-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
+| cpow      |                  |                 |                        |                      |                        | 7.3.8.2                | G.6.5.1                    |
++-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
+| csqrt     |                  |                 |                        |                      |                        | 7.3.8.3                | G.6.5.2                    |
++-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
+| carg      |                  |                 |                        |                      |                        | 7.3.9.1                | N/A                        |
++-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
+| cimag     |                  |                 |                        |                      |                        | 7.3.9.2                | N/A                        |
++-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
+| conj      |                  |                 |                        |                      |                        | 7.3.9.4                | N/A                        |
++-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
+| cproj     |                  |                 |                        |                      |                        | 7.3.9.5                | N/A                        |
++-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
+| creal     |                  |                 |                        |                      |                        | 7.3.9.6                | N/A                        |
++-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+

>From 3bac6b3c07522964c744184457f0e4b4ec11db50 Mon Sep 17 00:00:00 2001
From: Shourya Goel <shouryagoel10000 at gmail.com>
Date: Thu, 10 Oct 2024 20:03:57 +0530
Subject: [PATCH 06/11] Update complex-macros.h

---
 libc/include/llvm-libc-macros/complex-macros.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libc/include/llvm-libc-macros/complex-macros.h b/libc/include/llvm-libc-macros/complex-macros.h
index 3c239a04f8a6ad..962054aeb197e9 100644
--- a/libc/include/llvm-libc-macros/complex-macros.h
+++ b/libc/include/llvm-libc-macros/complex-macros.h
@@ -14,11 +14,11 @@
 #define __STDC_VERSION_COMPLEX_H__ 202311L
 
 #define complex _Complex
-#define _Complex_I (float _Complex)1.0fi
+#define _Complex_I ((float _Complex)1.0fi)
 
 #ifdef _Imaginary
 #define imaginary _Imaginary
-#define _Imaginary_I (float _Imaginary)1.0i
+#define _Imaginary_I ((float _Imaginary)1.0i)
 
 #define I _Imaginary_I
 #else

>From 33c4e0206d64788873157438742de125a5db2bd1 Mon Sep 17 00:00:00 2001
From: Shourya Goel <shouryagoel10000 at gmail.com>
Date: Thu, 10 Oct 2024 20:25:57 +0530
Subject: [PATCH 07/11] Update _Imaginary.h

---
 libc/include/llvm-libc-types/_Imaginary.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libc/include/llvm-libc-types/_Imaginary.h b/libc/include/llvm-libc-types/_Imaginary.h
index ad51bc1d37b569..0b2c17f79d2e6c 100644
--- a/libc/include/llvm-libc-types/_Imaginary.h
+++ b/libc/include/llvm-libc-types/_Imaginary.h
@@ -9,6 +9,7 @@
 #ifndef LLVM_LIBC_TYPES__Imaginary_H
 #define LLVM_LIBC_TYPES__Imaginary_H
 
-typedef /* TODO */ _Imaginary;
+// TODO: Define the _Imaginary type once clang or gcc supports it. 
+// typedef _Imaginary;
 
 #endif // LLVM_LIBC_TYPES__Imaginary_H

>From 1ceaffb53ee2fc891f6f12538cc5708979e40717 Mon Sep 17 00:00:00 2001
From: Sh0g0-1758 <shouryagoel10000 at gmail.com>
Date: Thu, 10 Oct 2024 20:28:33 +0530
Subject: [PATCH 08/11] remove _Imaginary

---
 libc/include/CMakeLists.txt               |  1 -
 libc/include/llvm-libc-types/_Imaginary.h | 15 ---------------
 2 files changed, 16 deletions(-)
 delete mode 100644 libc/include/llvm-libc-types/_Imaginary.h

diff --git a/libc/include/CMakeLists.txt b/libc/include/CMakeLists.txt
index 9a07445ec8b5b6..5deb5258d532fe 100644
--- a/libc/include/CMakeLists.txt
+++ b/libc/include/CMakeLists.txt
@@ -210,7 +210,6 @@ add_header_macro(
   DEPENDS
     .llvm_libc_common_h
     .llvm-libc-macros.complex_macros
-    .llvm-libc-types._Imaginary
 )
 
 add_header_macro(
diff --git a/libc/include/llvm-libc-types/_Imaginary.h b/libc/include/llvm-libc-types/_Imaginary.h
deleted file mode 100644
index 0b2c17f79d2e6c..00000000000000
--- a/libc/include/llvm-libc-types/_Imaginary.h
+++ /dev/null
@@ -1,15 +0,0 @@
-//===-- Definition of _Imaginary type -------------------------------------===//
-//
-// 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_TYPES__Imaginary_H
-#define LLVM_LIBC_TYPES__Imaginary_H
-
-// TODO: Define the _Imaginary type once clang or gcc supports it. 
-// typedef _Imaginary;
-
-#endif // LLVM_LIBC_TYPES__Imaginary_H

>From f5027c2454efea17fd1da76e28badc79e40fef6c Mon Sep 17 00:00:00 2001
From: Sh0g0-1758 <shouryagoel10000 at gmail.com>
Date: Thu, 10 Oct 2024 22:26:18 +0530
Subject: [PATCH 09/11] Add tests

---
 .../include/llvm-libc-macros/complex-macros.h | 10 ++-------
 libc/test/UnitTest/LibcTest.cpp               |  4 ++++
 libc/test/include/CMakeLists.txt              | 10 +++++++++
 libc/test/include/complex_test.cpp            | 22 +++++++++++++++++++
 4 files changed, 38 insertions(+), 8 deletions(-)
 create mode 100644 libc/test/include/complex_test.cpp

diff --git a/libc/include/llvm-libc-macros/complex-macros.h b/libc/include/llvm-libc-macros/complex-macros.h
index 962054aeb197e9..b2833bf09d3edc 100644
--- a/libc/include/llvm-libc-macros/complex-macros.h
+++ b/libc/include/llvm-libc-macros/complex-macros.h
@@ -15,15 +15,9 @@
 
 #define complex _Complex
 #define _Complex_I ((float _Complex)1.0fi)
-
-#ifdef _Imaginary
-#define imaginary _Imaginary
-#define _Imaginary_I ((float _Imaginary)1.0i)
-
-#define I _Imaginary_I
-#else
 #define I _Complex_I
-#endif
+
+// TODO: Add imaginary macros once GCC or Clang support them.
 
 #endif
 
diff --git a/libc/test/UnitTest/LibcTest.cpp b/libc/test/UnitTest/LibcTest.cpp
index ad5722f99a4369..8bbe1fe0abed7d 100644
--- a/libc/test/UnitTest/LibcTest.cpp
+++ b/libc/test/UnitTest/LibcTest.cpp
@@ -232,6 +232,10 @@ TEST_SPECIALIZATION(unsigned long long);
 
 TEST_SPECIALIZATION(bool);
 
+TEST_SPECIALIZATION(float _Complex);
+TEST_SPECIALIZATION(double _Complex);
+TEST_SPECIALIZATION(long double _Complex);
+
 // We cannot just use a single UInt128 specialization as that resolves to only
 // one type, UInt<128> or __uint128_t. We want both overloads as we want to
 #ifdef LIBC_TYPES_HAS_INT128
diff --git a/libc/test/include/CMakeLists.txt b/libc/test/include/CMakeLists.txt
index dd8f21bdd07aeb..05646a3c8c28c8 100644
--- a/libc/test/include/CMakeLists.txt
+++ b/libc/test/include/CMakeLists.txt
@@ -11,6 +11,16 @@ add_libc_test(
     libc.include.llvm-libc-macros.assert_macros
 )
 
+add_libc_test(
+  complex_test
+  SUITE
+    libc_include_tests
+  SRCS
+    complex_test.cpp
+  DEPENDS
+    libc.include.llvm-libc-macros.complex_macros
+)
+
 add_libc_test(
   sys_queue_test
   SUITE
diff --git a/libc/test/include/complex_test.cpp b/libc/test/include/complex_test.cpp
new file mode 100644
index 00000000000000..ec4547a66c0313
--- /dev/null
+++ b/libc/test/include/complex_test.cpp
@@ -0,0 +1,22 @@
+//===-- Unittests for complex ---------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDSList-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "include/llvm-libc-macros/complex-macros.h"
+#include "test/UnitTest/Test.h"
+
+TEST(LlvmLibcComplexTest, VersionMacro) {
+  EXPECT_EQ(__STDC_VERSION_COMPLEX_H__, 202311L);
+}
+
+TEST(LlvmLibcComplexTest, IMacro) {
+  EXPECT_EQ(I, 1.0fi);
+}
+
+TEST(LlvmLibcComplexTest, _Complex_IMacro) {
+  EXPECT_EQ(_Complex_I, 1.0fi);
+}

>From 7967075ccc1efd5d30a03e3ae2761501ed767f65 Mon Sep 17 00:00:00 2001
From: Sh0g0-1758 <shouryagoel10000 at gmail.com>
Date: Thu, 10 Oct 2024 23:28:10 +0530
Subject: [PATCH 10/11] Add FpBits

---
 libc/test/include/complex_test.cpp | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/libc/test/include/complex_test.cpp b/libc/test/include/complex_test.cpp
index ec4547a66c0313..6933a19ff6f239 100644
--- a/libc/test/include/complex_test.cpp
+++ b/libc/test/include/complex_test.cpp
@@ -7,6 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "include/llvm-libc-macros/complex-macros.h"
+#include "test/UnitTest/FPMatcher.h"
 #include "test/UnitTest/Test.h"
 
 TEST(LlvmLibcComplexTest, VersionMacro) {
@@ -14,9 +15,9 @@ TEST(LlvmLibcComplexTest, VersionMacro) {
 }
 
 TEST(LlvmLibcComplexTest, IMacro) {
-  EXPECT_EQ(I, 1.0fi);
+  EXPECT_FP_EQ(I, 1.0fi);
 }
 
 TEST(LlvmLibcComplexTest, _Complex_IMacro) {
-  EXPECT_EQ(_Complex_I, 1.0fi);
+  EXPECT_FP_EQ(_Complex_I, 1.0fi);
 }

>From 9c61d3acc422d6519ed6086382278334f0e1a24a Mon Sep 17 00:00:00 2001
From: Sh0g0-1758 <shouryagoel10000 at gmail.com>
Date: Thu, 10 Oct 2024 23:29:06 +0530
Subject: [PATCH 11/11] fmt

---
 libc/test/include/complex_test.cpp | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/libc/test/include/complex_test.cpp b/libc/test/include/complex_test.cpp
index 6933a19ff6f239..906ac53eb70a1e 100644
--- a/libc/test/include/complex_test.cpp
+++ b/libc/test/include/complex_test.cpp
@@ -14,10 +14,6 @@ TEST(LlvmLibcComplexTest, VersionMacro) {
   EXPECT_EQ(__STDC_VERSION_COMPLEX_H__, 202311L);
 }
 
-TEST(LlvmLibcComplexTest, IMacro) {
-  EXPECT_FP_EQ(I, 1.0fi);
-}
+TEST(LlvmLibcComplexTest, IMacro) { EXPECT_FP_EQ(I, 1.0fi); }
 
-TEST(LlvmLibcComplexTest, _Complex_IMacro) {
-  EXPECT_FP_EQ(_Complex_I, 1.0fi);
-}
+TEST(LlvmLibcComplexTest, _Complex_IMacro) { EXPECT_FP_EQ(_Complex_I, 1.0fi); }



More information about the libc-commits mailing list