complex.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. /* Copyright (C) 1997-2020 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(type, function, args) \
  76. __MATHDECL_1(type, function, args); \
  77. __MATHDECL_1(type, __CONCAT(__,function), args)
  78. #define __MATHDECL_1(type, function, args) \
  79. extern type __MATH_PRECNAME(function) args __THROW
  80. #define _Mdouble_ double
  81. #define __MATH_PRECNAME(name) name
  82. #include <bits/cmathcalls.h>
  83. #undef _Mdouble_
  84. #undef __MATH_PRECNAME
  85. /* Now the float versions. */
  86. #define _Mdouble_ float
  87. #define __MATH_PRECNAME(name) name##f
  88. #include <bits/cmathcalls.h>
  89. #undef _Mdouble_
  90. #undef __MATH_PRECNAME
  91. /* And the long double versions. It is non-critical to define them
  92. here unconditionally since `long double' is required in ISO C99. */
  93. #if !(defined __NO_LONG_DOUBLE_MATH && defined _LIBC) \
  94. || defined __LDBL_COMPAT
  95. # ifdef __LDBL_COMPAT
  96. # undef __MATHDECL_1
  97. # define __MATHDECL_1(type, function, args) \
  98. extern type __REDIRECT_NTH(__MATH_PRECNAME(function), args, function)
  99. # endif
  100. # define _Mdouble_ long double
  101. # define __MATH_PRECNAME(name) name##l
  102. # include <bits/cmathcalls.h>
  103. #endif
  104. #undef _Mdouble_
  105. #undef __MATH_PRECNAME
  106. #if (__HAVE_DISTINCT_FLOAT16 || (__HAVE_FLOAT16 && !defined _LIBC)) \
  107. && __GLIBC_USE (IEC_60559_TYPES_EXT)
  108. # undef _Mdouble_complex_
  109. # define _Mdouble_complex_ __CFLOAT16
  110. # define _Mdouble_ _Float16
  111. # define __MATH_PRECNAME(name) name##f16
  112. # include <bits/cmathcalls.h>
  113. # undef _Mdouble_
  114. # undef __MATH_PRECNAME
  115. # undef _Mdouble_complex_
  116. #endif
  117. #if (__HAVE_DISTINCT_FLOAT32 || (__HAVE_FLOAT32 && !defined _LIBC)) \
  118. && __GLIBC_USE (IEC_60559_TYPES_EXT)
  119. # undef _Mdouble_complex_
  120. # define _Mdouble_complex_ __CFLOAT32
  121. # define _Mdouble_ _Float32
  122. # define __MATH_PRECNAME(name) name##f32
  123. # include <bits/cmathcalls.h>
  124. # undef _Mdouble_
  125. # undef __MATH_PRECNAME
  126. # undef _Mdouble_complex_
  127. #endif
  128. #if (__HAVE_DISTINCT_FLOAT64 || (__HAVE_FLOAT64 && !defined _LIBC)) \
  129. && __GLIBC_USE (IEC_60559_TYPES_EXT)
  130. # undef _Mdouble_complex_
  131. # define _Mdouble_complex_ __CFLOAT64
  132. # define _Mdouble_ _Float64
  133. # define __MATH_PRECNAME(name) name##f64
  134. # include <bits/cmathcalls.h>
  135. # undef _Mdouble_
  136. # undef __MATH_PRECNAME
  137. # undef _Mdouble_complex_
  138. #endif
  139. #if (__HAVE_DISTINCT_FLOAT128 || (__HAVE_FLOAT128 && !defined _LIBC)) \
  140. && __GLIBC_USE (IEC_60559_TYPES_EXT)
  141. # undef _Mdouble_complex_
  142. # define _Mdouble_complex_ __CFLOAT128
  143. # define _Mdouble_ _Float128
  144. # define __MATH_PRECNAME(name) name##f128
  145. # include <bits/cmathcalls.h>
  146. # undef _Mdouble_
  147. # undef __MATH_PRECNAME
  148. # undef _Mdouble_complex_
  149. #endif
  150. #if (__HAVE_DISTINCT_FLOAT32X || (__HAVE_FLOAT32X && !defined _LIBC)) \
  151. && __GLIBC_USE (IEC_60559_TYPES_EXT)
  152. # undef _Mdouble_complex_
  153. # define _Mdouble_complex_ __CFLOAT32X
  154. # define _Mdouble_ _Float32x
  155. # define __MATH_PRECNAME(name) name##f32x
  156. # include <bits/cmathcalls.h>
  157. # undef _Mdouble_
  158. # undef __MATH_PRECNAME
  159. # undef _Mdouble_complex_
  160. #endif
  161. #if (__HAVE_DISTINCT_FLOAT64X || (__HAVE_FLOAT64X && !defined _LIBC)) \
  162. && __GLIBC_USE (IEC_60559_TYPES_EXT)
  163. # undef _Mdouble_complex_
  164. # define _Mdouble_complex_ __CFLOAT64X
  165. # define _Mdouble_ _Float64x
  166. # define __MATH_PRECNAME(name) name##f64x
  167. # include <bits/cmathcalls.h>
  168. # undef _Mdouble_
  169. # undef __MATH_PRECNAME
  170. # undef _Mdouble_complex_
  171. #endif
  172. #if (__HAVE_DISTINCT_FLOAT128X || (__HAVE_FLOAT128X && !defined _LIBC)) \
  173. && __GLIBC_USE (IEC_60559_TYPES_EXT)
  174. # undef _Mdouble_complex_
  175. # define _Mdouble_complex_ __CFLOAT128X
  176. # define _Mdouble_ _Float128x
  177. # define __MATH_PRECNAME(name) name##f128x
  178. # include <bits/cmathcalls.h>
  179. # undef _Mdouble_
  180. # undef __MATH_PRECNAME
  181. # undef _Mdouble_complex_
  182. #endif
  183. #undef __MATHDECL_1
  184. #undef __MATHDECL
  185. #undef __MATHCALL
  186. __END_DECLS
  187. #endif /* complex.h */