complex.h 7.9 KB

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