| 1 | /* Copyright (C) 1997-2026 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 | #if __GLIBC_USE (ISOC23) |
| 37 | # define __STDC_VERSION_COMPLEX_H__ 202311L |
| 38 | #endif |
| 39 | |
| 40 | /* We might need to add support for more compilers here. But since ISO |
| 41 | C99 is out hopefully all maintained compilers will soon provide the data |
| 42 | types `float complex' and `double complex'. */ |
| 43 | #if __GNUC_PREREQ (2, 7) && !__GNUC_PREREQ (2, 97) |
| 44 | # define _Complex __complex__ |
| 45 | #endif |
| 46 | |
| 47 | #define complex		_Complex |
| 48 | |
| 49 | /* Narrowest imaginary unit. This depends on the floating-point |
| 50 | evaluation method. |
| 51 | XXX This probably has to go into a gcc related file. */ |
| 52 | #define _Complex_I	(__extension__ 1.0iF) |
| 53 | |
| 54 | /* Another more descriptive name is `I'. |
| 55 | XXX Once we have the imaginary support switch this to _Imaginary_I. */ |
| 56 | #undef I |
| 57 | #define I _Complex_I |
| 58 | |
| 59 | #if defined __USE_ISOC11 \ |
| 60 | && (__GNUC_PREREQ (4, 7) || __glibc_clang_prereq (12, 0)) |
| 61 | /* Macros to expand into expression of specified complex type. */ |
| 62 | # define CMPLX(x, y) __builtin_complex ((double) (x), (double) (y)) |
| 63 | # define CMPLXF(x, y) __builtin_complex ((float) (x), (float) (y)) |
| 64 | # define CMPLXL(x, y) __builtin_complex ((long double) (x), (long double) (y)) |
| 65 | #endif |
| 66 | |
| 67 | #if __HAVE_FLOAT16 && __GLIBC_USE (IEC_60559_TYPES_EXT) |
| 68 | # define CMPLXF16(x, y) __builtin_complex ((_Float16) (x), (_Float16) (y)) |
| 69 | #endif |
| 70 | |
| 71 | #if __HAVE_FLOAT32 && __GLIBC_USE (IEC_60559_TYPES_EXT) |
| 72 | # define CMPLXF32(x, y) __builtin_complex ((_Float32) (x), (_Float32) (y)) |
| 73 | #endif |
| 74 | |
| 75 | #if __HAVE_FLOAT64 && __GLIBC_USE (IEC_60559_TYPES_EXT) |
| 76 | # define CMPLXF64(x, y) __builtin_complex ((_Float64) (x), (_Float64) (y)) |
| 77 | #endif |
| 78 | |
| 79 | #if __HAVE_FLOAT128 && __GLIBC_USE (IEC_60559_TYPES_EXT) |
| 80 | # define CMPLXF128(x, y) __builtin_complex ((_Float128) (x), (_Float128) (y)) |
| 81 | #endif |
| 82 | |
| 83 | #if __HAVE_FLOAT32X && __GLIBC_USE (IEC_60559_TYPES_EXT) |
| 84 | # define CMPLXF32X(x, y) __builtin_complex ((_Float32x) (x), (_Float32x) (y)) |
| 85 | #endif |
| 86 | |
| 87 | #if __HAVE_FLOAT64X && __GLIBC_USE (IEC_60559_TYPES_EXT) |
| 88 | # define CMPLXF64X(x, y) __builtin_complex ((_Float64x) (x), (_Float64x) (y)) |
| 89 | #endif |
| 90 | |
| 91 | #if __HAVE_FLOAT128X && __GLIBC_USE (IEC_60559_TYPES_EXT) |
| 92 | # define CMPLXF128X(x, y)					\ |
| 93 | __builtin_complex ((_Float128x) (x), (_Float128x) (y)) |
| 94 | #endif |
| 95 | |
| 96 | /* The file <bits/cmathcalls.h> contains the prototypes for all the |
| 97 | actual math functions. These macros are used for those prototypes, |
| 98 | so we can easily declare each function as both `name' and `__name', |
| 99 | and can declare the float versions `namef' and `__namef'. */ |
| 100 | |
| 101 | #define __MATHCALL(function, args)	\ |
| 102 | __MATHDECL (_Mdouble_complex_,function, args) |
| 103 | #define __MATHDECL_IMPL(type, function, args) \ |
| 104 | __MATHDECL_1(type, function, args); \ |
| 105 | __MATHDECL_1(type, __CONCAT(__,function), args) |
| 106 | #define __MATHDECL(type, function, args) \ |
| 107 | __MATHDECL_IMPL(type, function, args) |
| 108 | #define __MATHDECL_1_IMPL(type, function, args) \ |
| 109 | extern type __MATH_PRECNAME(function) args __THROW |
| 110 | #define __MATHDECL_1(type, function, args) \ |
| 111 | __MATHDECL_1_IMPL(type, function, args) |
| 112 | |
| 113 | #define _Mdouble_ 		double |
| 114 | #define __MATH_PRECNAME(name)	name |
| 115 | #include <bits/cmathcalls.h> |
| 116 | #undef	_Mdouble_ |
| 117 | #undef	__MATH_PRECNAME |
| 118 | |
| 119 | /* Now the float versions. */ |
| 120 | #define _Mdouble_ 		float |
| 121 | #define __MATH_PRECNAME(name)	name##f |
| 122 | #include <bits/cmathcalls.h> |
| 123 | #undef	_Mdouble_ |
| 124 | #undef	__MATH_PRECNAME |
| 125 | |
| 126 | /* And the long double versions. It is non-critical to define them |
| 127 | here unconditionally since `long double' is required in ISO C99. */ |
| 128 | #if !(defined __NO_LONG_DOUBLE_MATH && defined _LIBC)	\ |
| 129 | || defined __LDBL_COMPAT |
| 130 | # ifdef __LDBL_COMPAT |
| 131 | # undef __MATHDECL_1 |
| 132 | # define __MATHDECL_1(type, function, args) \ |
| 133 | extern type __REDIRECT_NTH(__MATH_PRECNAME(function), args, function) |
| 134 | # elif __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1 |
| 135 | # undef __MATHDECL_1 |
| 136 | # undef __MATHDECL |
| 137 | # define __REDIR_TO(function) \ |
| 138 | __ ## function ## ieee128 |
| 139 | # define __MATHDECL_1(type, function, alias, args) \ |
| 140 | extern type __REDIRECT_NTH(__MATH_PRECNAME(function), args, alias) |
| 141 | #define __MATHDECL(type, function, args) \ |
| 142 | __MATHDECL_1(type, function, __REDIR_TO(function), args); \ |
| 143 | __MATHDECL_1(type, __CONCAT(__,function), __REDIR_TO(function), args) |
| 144 | # endif |
| 145 | |
| 146 | # define _Mdouble_ 		long double |
| 147 | # define __MATH_PRECNAME(name)	name##l |
| 148 | # include <bits/cmathcalls.h> |
| 149 | # if defined __LDBL_COMPAT \ |
| 150 | || __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1 |
| 151 | # undef __REDIR_TO |
| 152 | # undef __MATHDECL_1 |
| 153 | # undef __MATHDECL |
| 154 | #define __MATHDECL(type, function, args) \ |
| 155 | __MATHDECL_IMPL(type, function, args) |
| 156 | # define __MATHDECL_1(type, function, args) \ |
| 157 | __MATHDECL_1_IMPL(type, function, args) |
| 158 | # endif |
| 159 | #endif |
| 160 | #undef	_Mdouble_ |
| 161 | #undef	__MATH_PRECNAME |
| 162 | |
| 163 | #if (__HAVE_DISTINCT_FLOAT16 || (__HAVE_FLOAT16 && !defined _LIBC)) \ |
| 164 | && __GLIBC_USE (IEC_60559_TYPES_EXT) |
| 165 | # undef _Mdouble_complex_ |
| 166 | # define _Mdouble_complex_	__CFLOAT16 |
| 167 | # define _Mdouble_		_Float16 |
| 168 | # define __MATH_PRECNAME(name)	name##f16 |
| 169 | # include <bits/cmathcalls.h> |
| 170 | # undef _Mdouble_ |
| 171 | # undef __MATH_PRECNAME |
| 172 | # undef _Mdouble_complex_ |
| 173 | #endif |
| 174 | |
| 175 | #if (__HAVE_DISTINCT_FLOAT32 || (__HAVE_FLOAT32 && !defined _LIBC)) \ |
| 176 | && __GLIBC_USE (IEC_60559_TYPES_EXT) |
| 177 | # undef _Mdouble_complex_ |
| 178 | # define _Mdouble_complex_	__CFLOAT32 |
| 179 | # define _Mdouble_		_Float32 |
| 180 | # define __MATH_PRECNAME(name)	name##f32 |
| 181 | # include <bits/cmathcalls.h> |
| 182 | # undef _Mdouble_ |
| 183 | # undef __MATH_PRECNAME |
| 184 | # undef _Mdouble_complex_ |
| 185 | #endif |
| 186 | |
| 187 | #if (__HAVE_DISTINCT_FLOAT64 || (__HAVE_FLOAT64 && !defined _LIBC)) \ |
| 188 | && __GLIBC_USE (IEC_60559_TYPES_EXT) |
| 189 | # undef _Mdouble_complex_ |
| 190 | # define _Mdouble_complex_	__CFLOAT64 |
| 191 | # define _Mdouble_		_Float64 |
| 192 | # define __MATH_PRECNAME(name)	name##f64 |
| 193 | # include <bits/cmathcalls.h> |
| 194 | # undef _Mdouble_ |
| 195 | # undef __MATH_PRECNAME |
| 196 | # undef _Mdouble_complex_ |
| 197 | #endif |
| 198 | |
| 199 | #if (__HAVE_DISTINCT_FLOAT128 || (__HAVE_FLOAT128 && !defined _LIBC)) \ |
| 200 | && __GLIBC_USE (IEC_60559_TYPES_EXT) |
| 201 | # undef _Mdouble_complex_ |
| 202 | # define _Mdouble_complex_	__CFLOAT128 |
| 203 | # define _Mdouble_		_Float128 |
| 204 | # define __MATH_PRECNAME(name)	name##f128 |
| 205 | # include <bits/cmathcalls.h> |
| 206 | # undef _Mdouble_ |
| 207 | # undef __MATH_PRECNAME |
| 208 | # undef _Mdouble_complex_ |
| 209 | #endif |
| 210 | |
| 211 | #if (__HAVE_DISTINCT_FLOAT32X || (__HAVE_FLOAT32X && !defined _LIBC)) \ |
| 212 | && __GLIBC_USE (IEC_60559_TYPES_EXT) |
| 213 | # undef _Mdouble_complex_ |
| 214 | # define _Mdouble_complex_	__CFLOAT32X |
| 215 | # define _Mdouble_		_Float32x |
| 216 | # define __MATH_PRECNAME(name)	name##f32x |
| 217 | # include <bits/cmathcalls.h> |
| 218 | # undef _Mdouble_ |
| 219 | # undef __MATH_PRECNAME |
| 220 | # undef _Mdouble_complex_ |
| 221 | #endif |
| 222 | |
| 223 | #if (__HAVE_DISTINCT_FLOAT64X || (__HAVE_FLOAT64X && !defined _LIBC)) \ |
| 224 | && __GLIBC_USE (IEC_60559_TYPES_EXT) |
| 225 | # undef _Mdouble_complex_ |
| 226 | # define _Mdouble_complex_	__CFLOAT64X |
| 227 | # define _Mdouble_		_Float64x |
| 228 | # define __MATH_PRECNAME(name)	name##f64x |
| 229 | # include <bits/cmathcalls.h> |
| 230 | # undef _Mdouble_ |
| 231 | # undef __MATH_PRECNAME |
| 232 | # undef _Mdouble_complex_ |
| 233 | #endif |
| 234 | |
| 235 | #if (__HAVE_DISTINCT_FLOAT128X || (__HAVE_FLOAT128X && !defined _LIBC)) \ |
| 236 | && __GLIBC_USE (IEC_60559_TYPES_EXT) |
| 237 | # undef _Mdouble_complex_ |
| 238 | # define _Mdouble_complex_	__CFLOAT128X |
| 239 | # define _Mdouble_		_Float128x |
| 240 | # define __MATH_PRECNAME(name)	name##f128x |
| 241 | # include <bits/cmathcalls.h> |
| 242 | # undef _Mdouble_ |
| 243 | # undef __MATH_PRECNAME |
| 244 | # undef _Mdouble_complex_ |
| 245 | #endif |
| 246 | |
| 247 | #undef	__MATHDECL_1_IMPL |
| 248 | #undef	__MATHDECL_1 |
| 249 | #undef	__MATHDECL |
| 250 | #undef	__MATHCALL |
| 251 | |
| 252 | __END_DECLS |
| 253 | |
| 254 | #endif /* complex.h */ |