master
1/* Copyright (C) 1997-2025 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
17
18/*
19 * ISO C99: 7.3 Complex arithmetic <complex.h>
20 */
21
22#ifndef _COMPLEX_H
23#define _COMPLEX_H 1
24
25#define __GLIBC_INTERNAL_STARTING_HEADER_IMPLEMENTATION
26#include <bits/libc-header-start.h>
27
28/* Get general and ISO C99 specific information. */
29#include <bits/mathdef.h>
30
31/* Gather machine-dependent _FloatN type support. */
32#include <bits/floatn.h>
33
34__BEGIN_DECLS
35
36/* We might need to add support for more compilers here. But since ISO
37 C99 is out hopefully all maintained compilers will soon provide the data
38 types `float complex' and `double complex'. */
39#if __GNUC_PREREQ (2, 7) && !__GNUC_PREREQ (2, 97)
40# define _Complex __complex__
41#endif
42
43#define complex _Complex
44
45/* Narrowest imaginary unit. This depends on the floating-point
46 evaluation method.
47 XXX This probably has to go into a gcc related file. */
48#define _Complex_I (__extension__ 1.0iF)
49
50/* Another more descriptive name is `I'.
51 XXX Once we have the imaginary support switch this to _Imaginary_I. */
52#undef I
53#define I _Complex_I
54
55#if defined __USE_ISOC11 \
56 && (__GNUC_PREREQ (4, 7) || __glibc_clang_prereq (12, 0))
57/* Macros to expand into expression of specified complex type. */
58# define CMPLX(x, y) __builtin_complex ((double) (x), (double) (y))
59# define CMPLXF(x, y) __builtin_complex ((float) (x), (float) (y))
60# define CMPLXL(x, y) __builtin_complex ((long double) (x), (long double) (y))
61#endif
62
63#if __HAVE_FLOAT16 && __GLIBC_USE (IEC_60559_TYPES_EXT)
64# define CMPLXF16(x, y) __builtin_complex ((_Float16) (x), (_Float16) (y))
65#endif
66
67#if __HAVE_FLOAT32 && __GLIBC_USE (IEC_60559_TYPES_EXT)
68# define CMPLXF32(x, y) __builtin_complex ((_Float32) (x), (_Float32) (y))
69#endif
70
71#if __HAVE_FLOAT64 && __GLIBC_USE (IEC_60559_TYPES_EXT)
72# define CMPLXF64(x, y) __builtin_complex ((_Float64) (x), (_Float64) (y))
73#endif
74
75#if __HAVE_FLOAT128 && __GLIBC_USE (IEC_60559_TYPES_EXT)
76# define CMPLXF128(x, y) __builtin_complex ((_Float128) (x), (_Float128) (y))
77#endif
78
79#if __HAVE_FLOAT32X && __GLIBC_USE (IEC_60559_TYPES_EXT)
80# define CMPLXF32X(x, y) __builtin_complex ((_Float32x) (x), (_Float32x) (y))
81#endif
82
83#if __HAVE_FLOAT64X && __GLIBC_USE (IEC_60559_TYPES_EXT)
84# define CMPLXF64X(x, y) __builtin_complex ((_Float64x) (x), (_Float64x) (y))
85#endif
86
87#if __HAVE_FLOAT128X && __GLIBC_USE (IEC_60559_TYPES_EXT)
88# define CMPLXF128X(x, y) \
89 __builtin_complex ((_Float128x) (x), (_Float128x) (y))
90#endif
91
92/* The file <bits/cmathcalls.h> contains the prototypes for all the
93 actual math functions. These macros are used for those prototypes,
94 so we can easily declare each function as both `name' and `__name',
95 and can declare the float versions `namef' and `__namef'. */
96
97#define __MATHCALL(function, args) \
98 __MATHDECL (_Mdouble_complex_,function, args)
99#define __MATHDECL_IMPL(type, function, args) \
100 __MATHDECL_1(type, function, args); \
101 __MATHDECL_1(type, __CONCAT(__,function), args)
102#define __MATHDECL(type, function, args) \
103 __MATHDECL_IMPL(type, function, args)
104#define __MATHDECL_1_IMPL(type, function, args) \
105 extern type __MATH_PRECNAME(function) args __THROW
106#define __MATHDECL_1(type, function, args) \
107 __MATHDECL_1_IMPL(type, function, args)
108
109#define _Mdouble_ double
110#define __MATH_PRECNAME(name) name
111#include <bits/cmathcalls.h>
112#undef _Mdouble_
113#undef __MATH_PRECNAME
114
115/* Now the float versions. */
116#define _Mdouble_ float
117#define __MATH_PRECNAME(name) name##f
118#include <bits/cmathcalls.h>
119#undef _Mdouble_
120#undef __MATH_PRECNAME
121
122/* And the long double versions. It is non-critical to define them
123 here unconditionally since `long double' is required in ISO C99. */
124#if !(defined __NO_LONG_DOUBLE_MATH && defined _LIBC) \
125 || defined __LDBL_COMPAT
126# ifdef __LDBL_COMPAT
127# undef __MATHDECL_1
128# define __MATHDECL_1(type, function, args) \
129 extern type __REDIRECT_NTH(__MATH_PRECNAME(function), args, function)
130# elif __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1
131# undef __MATHDECL_1
132# undef __MATHDECL
133# define __REDIR_TO(function) \
134 __ ## function ## ieee128
135# define __MATHDECL_1(type, function, alias, args) \
136 extern type __REDIRECT_NTH(__MATH_PRECNAME(function), args, alias)
137#define __MATHDECL(type, function, args) \
138 __MATHDECL_1(type, function, __REDIR_TO(function), args); \
139 __MATHDECL_1(type, __CONCAT(__,function), __REDIR_TO(function), args)
140# endif
141
142# define _Mdouble_ long double
143# define __MATH_PRECNAME(name) name##l
144# include <bits/cmathcalls.h>
145# if defined __LDBL_COMPAT \
146 || __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1
147# undef __REDIR_TO
148# undef __MATHDECL_1
149# undef __MATHDECL
150#define __MATHDECL(type, function, args) \
151 __MATHDECL_IMPL(type, function, args)
152# define __MATHDECL_1(type, function, args) \
153 __MATHDECL_1_IMPL(type, function, args)
154# endif
155#endif
156#undef _Mdouble_
157#undef __MATH_PRECNAME
158
159#if (__HAVE_DISTINCT_FLOAT16 || (__HAVE_FLOAT16 && !defined _LIBC)) \
160 && __GLIBC_USE (IEC_60559_TYPES_EXT)
161# undef _Mdouble_complex_
162# define _Mdouble_complex_ __CFLOAT16
163# define _Mdouble_ _Float16
164# define __MATH_PRECNAME(name) name##f16
165# include <bits/cmathcalls.h>
166# undef _Mdouble_
167# undef __MATH_PRECNAME
168# undef _Mdouble_complex_
169#endif
170
171#if (__HAVE_DISTINCT_FLOAT32 || (__HAVE_FLOAT32 && !defined _LIBC)) \
172 && __GLIBC_USE (IEC_60559_TYPES_EXT)
173# undef _Mdouble_complex_
174# define _Mdouble_complex_ __CFLOAT32
175# define _Mdouble_ _Float32
176# define __MATH_PRECNAME(name) name##f32
177# include <bits/cmathcalls.h>
178# undef _Mdouble_
179# undef __MATH_PRECNAME
180# undef _Mdouble_complex_
181#endif
182
183#if (__HAVE_DISTINCT_FLOAT64 || (__HAVE_FLOAT64 && !defined _LIBC)) \
184 && __GLIBC_USE (IEC_60559_TYPES_EXT)
185# undef _Mdouble_complex_
186# define _Mdouble_complex_ __CFLOAT64
187# define _Mdouble_ _Float64
188# define __MATH_PRECNAME(name) name##f64
189# include <bits/cmathcalls.h>
190# undef _Mdouble_
191# undef __MATH_PRECNAME
192# undef _Mdouble_complex_
193#endif
194
195#if (__HAVE_DISTINCT_FLOAT128 || (__HAVE_FLOAT128 && !defined _LIBC)) \
196 && __GLIBC_USE (IEC_60559_TYPES_EXT)
197# undef _Mdouble_complex_
198# define _Mdouble_complex_ __CFLOAT128
199# define _Mdouble_ _Float128
200# define __MATH_PRECNAME(name) name##f128
201# include <bits/cmathcalls.h>
202# undef _Mdouble_
203# undef __MATH_PRECNAME
204# undef _Mdouble_complex_
205#endif
206
207#if (__HAVE_DISTINCT_FLOAT32X || (__HAVE_FLOAT32X && !defined _LIBC)) \
208 && __GLIBC_USE (IEC_60559_TYPES_EXT)
209# undef _Mdouble_complex_
210# define _Mdouble_complex_ __CFLOAT32X
211# define _Mdouble_ _Float32x
212# define __MATH_PRECNAME(name) name##f32x
213# include <bits/cmathcalls.h>
214# undef _Mdouble_
215# undef __MATH_PRECNAME
216# undef _Mdouble_complex_
217#endif
218
219#if (__HAVE_DISTINCT_FLOAT64X || (__HAVE_FLOAT64X && !defined _LIBC)) \
220 && __GLIBC_USE (IEC_60559_TYPES_EXT)
221# undef _Mdouble_complex_
222# define _Mdouble_complex_ __CFLOAT64X
223# define _Mdouble_ _Float64x
224# define __MATH_PRECNAME(name) name##f64x
225# include <bits/cmathcalls.h>
226# undef _Mdouble_
227# undef __MATH_PRECNAME
228# undef _Mdouble_complex_
229#endif
230
231#if (__HAVE_DISTINCT_FLOAT128X || (__HAVE_FLOAT128X && !defined _LIBC)) \
232 && __GLIBC_USE (IEC_60559_TYPES_EXT)
233# undef _Mdouble_complex_
234# define _Mdouble_complex_ __CFLOAT128X
235# define _Mdouble_ _Float128x
236# define __MATH_PRECNAME(name) name##f128x
237# include <bits/cmathcalls.h>
238# undef _Mdouble_
239# undef __MATH_PRECNAME
240# undef _Mdouble_complex_
241#endif
242
243#undef __MATHDECL_1_IMPL
244#undef __MATHDECL_1
245#undef __MATHDECL
246#undef __MATHCALL
247
248__END_DECLS
249
250#endif /* complex.h */