complex.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /* Copyright (C) 1997-2016 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. <http://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. #include <features.h>
  20. /* Get general and ISO C99 specific information. */
  21. #include <bits/mathdef.h>
  22. __BEGIN_DECLS
  23. /* We might need to add support for more compilers here. But since ISO
  24. C99 is out hopefully all maintained compilers will soon provide the data
  25. types `float complex' and `double complex'. */
  26. #if __GNUC_PREREQ (2, 7) && !__GNUC_PREREQ (2, 97)
  27. # define _Complex __complex__
  28. #endif
  29. #define complex _Complex
  30. /* Narrowest imaginary unit. This depends on the floating-point
  31. evaluation method.
  32. XXX This probably has to go into a gcc related file. */
  33. #define _Complex_I (__extension__ 1.0iF)
  34. /* Another more descriptive name is `I'.
  35. XXX Once we have the imaginary support switch this to _Imaginary_I. */
  36. #undef I
  37. #define I _Complex_I
  38. #if defined __USE_ISOC11 && __GNUC_PREREQ (4, 7)
  39. /* Macros to expand into expression of specified complex type. */
  40. # define CMPLX(x, y) __builtin_complex ((double) (x), (double) (y))
  41. # define CMPLXF(x, y) __builtin_complex ((float) (x), (float) (y))
  42. # define CMPLXL(x, y) __builtin_complex ((long double) (x), (long double) (y))
  43. #endif
  44. /* The file <bits/cmathcalls.h> contains the prototypes for all the
  45. actual math functions. These macros are used for those prototypes,
  46. so we can easily declare each function as both `name' and `__name',
  47. and can declare the float versions `namef' and `__namef'. */
  48. #define __MATHCALL(function, args) \
  49. __MATHDECL (_Mdouble_complex_,function, args)
  50. #define __MATHDECL(type, function, args) \
  51. __MATHDECL_1(type, function, args); \
  52. __MATHDECL_1(type, __CONCAT(__,function), args)
  53. #define __MATHDECL_1(type, function, args) \
  54. extern type __MATH_PRECNAME(function) args __THROW
  55. #define _Mdouble_ double
  56. #define __MATH_PRECNAME(name) name
  57. #include <bits/cmathcalls.h>
  58. #undef _Mdouble_
  59. #undef __MATH_PRECNAME
  60. /* Now the float versions. */
  61. #ifndef _Mfloat_
  62. # define _Mfloat_ float
  63. #endif
  64. #define _Mdouble_ _Mfloat_
  65. #define __MATH_PRECNAME(name) name##f
  66. #include <bits/cmathcalls.h>
  67. #undef _Mdouble_
  68. #undef __MATH_PRECNAME
  69. /* And the long double versions. It is non-critical to define them
  70. here unconditionally since `long double' is required in ISO C99. */
  71. #if !(defined __NO_LONG_DOUBLE_MATH && defined _LIBC) \
  72. || defined __LDBL_COMPAT
  73. # ifdef __LDBL_COMPAT
  74. # undef __MATHDECL_1
  75. # define __MATHDECL_1(type, function, args) \
  76. extern type __REDIRECT_NTH(__MATH_PRECNAME(function), args, function)
  77. # endif
  78. # ifndef _Mlong_double_
  79. # define _Mlong_double_ long double
  80. # endif
  81. # define _Mdouble_ _Mlong_double_
  82. # define __MATH_PRECNAME(name) name##l
  83. # include <bits/cmathcalls.h>
  84. #endif
  85. #undef _Mdouble_
  86. #undef __MATH_PRECNAME
  87. #undef __MATHDECL_1
  88. #undef __MATHDECL
  89. #undef __MATHCALL
  90. __END_DECLS
  91. #endif /* complex.h */