complex.h 8.1 KB

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