You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
5.3KB

  1. /* Copyright (C) 2004-2020 Free Software Foundation, Inc.
  2. Contributed by Apple, Inc.
  3. This file is part of GCC.
  4. GCC is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3, or (at your option)
  7. any later version.
  8. GCC is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. Under Section 7 of GPL version 3, you are granted additional
  13. permissions described in the GCC Runtime Library Exception, version
  14. 3.1, as published by the Free Software Foundation.
  15. You should have received a copy of the GNU General Public License and
  16. a copy of the GCC Runtime Library Exception along with this program;
  17. see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  18. <http://www.gnu.org/licenses/>. */
  19. /*
  20. * ISO C Standard: 7.22 Type-generic math <tgmath.h>
  21. */
  22. #ifndef _TGMATH_H
  23. #define _TGMATH_H
  24. #include <math.h>
  25. #ifndef __cplusplus
  26. #include <complex.h>
  27. /* Naming convention: generic macros are defining using
  28. __TGMATH_CPLX*, __TGMATH_REAL*, and __TGMATH_CPLX_ONLY. _CPLX
  29. means the generic argument(s) may be real or complex, _REAL means
  30. real only, _CPLX means complex only. If there is no suffix, we are
  31. defining a function of one argument. If the suffix is _n
  32. it is a function of n arguments. We only define these macros for
  33. values of n that are needed. */
  34. #define __TGMATH_CPLX(z,R,C) \
  35. __builtin_tgmath (R##f, R, R##l, C##f, C, C##l, (z))
  36. #define __TGMATH_CPLX_2(z1,z2,R,C) \
  37. __builtin_tgmath (R##f, R, R##l, C##f, C, C##l, (z1), (z2))
  38. #define __TGMATH_REAL(x,R) \
  39. __builtin_tgmath (R##f, R, R##l, (x))
  40. #define __TGMATH_REAL_2(x,y,R) \
  41. __builtin_tgmath (R##f, R, R##l, (x), (y))
  42. #define __TGMATH_REAL_3(x,y,z,R) \
  43. __builtin_tgmath (R##f, R, R##l, (x), (y), (z))
  44. #define __TGMATH_CPLX_ONLY(z,C) \
  45. __builtin_tgmath (C##f, C, C##l, (z))
  46. /* Functions defined in both <math.h> and <complex.h> (7.22p4) */
  47. #define acos(z) __TGMATH_CPLX(z, acos, cacos)
  48. #define asin(z) __TGMATH_CPLX(z, asin, casin)
  49. #define atan(z) __TGMATH_CPLX(z, atan, catan)
  50. #define acosh(z) __TGMATH_CPLX(z, acosh, cacosh)
  51. #define asinh(z) __TGMATH_CPLX(z, asinh, casinh)
  52. #define atanh(z) __TGMATH_CPLX(z, atanh, catanh)
  53. #define cos(z) __TGMATH_CPLX(z, cos, ccos)
  54. #define sin(z) __TGMATH_CPLX(z, sin, csin)
  55. #define tan(z) __TGMATH_CPLX(z, tan, ctan)
  56. #define cosh(z) __TGMATH_CPLX(z, cosh, ccosh)
  57. #define sinh(z) __TGMATH_CPLX(z, sinh, csinh)
  58. #define tanh(z) __TGMATH_CPLX(z, tanh, ctanh)
  59. #define exp(z) __TGMATH_CPLX(z, exp, cexp)
  60. #define log(z) __TGMATH_CPLX(z, log, clog)
  61. #define pow(z1,z2) __TGMATH_CPLX_2(z1, z2, pow, cpow)
  62. #define sqrt(z) __TGMATH_CPLX(z, sqrt, csqrt)
  63. #define fabs(z) __TGMATH_CPLX(z, fabs, cabs)
  64. /* Functions defined in <math.h> only (7.22p5) */
  65. #define atan2(x,y) __TGMATH_REAL_2(x, y, atan2)
  66. #define cbrt(x) __TGMATH_REAL(x, cbrt)
  67. #define ceil(x) __TGMATH_REAL(x, ceil)
  68. #define copysign(x,y) __TGMATH_REAL_2(x, y, copysign)
  69. #define erf(x) __TGMATH_REAL(x, erf)
  70. #define erfc(x) __TGMATH_REAL(x, erfc)
  71. #define exp2(x) __TGMATH_REAL(x, exp2)
  72. #define expm1(x) __TGMATH_REAL(x, expm1)
  73. #define fdim(x,y) __TGMATH_REAL_2(x, y, fdim)
  74. #define floor(x) __TGMATH_REAL(x, floor)
  75. #define fma(x,y,z) __TGMATH_REAL_3(x, y, z, fma)
  76. #define fmax(x,y) __TGMATH_REAL_2(x, y, fmax)
  77. #define fmin(x,y) __TGMATH_REAL_2(x, y, fmin)
  78. #define fmod(x,y) __TGMATH_REAL_2(x, y, fmod)
  79. #define frexp(x,y) __TGMATH_REAL_2(x, y, frexp)
  80. #define hypot(x,y) __TGMATH_REAL_2(x, y, hypot)
  81. #define ilogb(x) __TGMATH_REAL(x, ilogb)
  82. #define ldexp(x,y) __TGMATH_REAL_2(x, y, ldexp)
  83. #define lgamma(x) __TGMATH_REAL(x, lgamma)
  84. #define llrint(x) __TGMATH_REAL(x, llrint)
  85. #define llround(x) __TGMATH_REAL(x, llround)
  86. #define log10(x) __TGMATH_REAL(x, log10)
  87. #define log1p(x) __TGMATH_REAL(x, log1p)
  88. #define log2(x) __TGMATH_REAL(x, log2)
  89. #define logb(x) __TGMATH_REAL(x, logb)
  90. #define lrint(x) __TGMATH_REAL(x, lrint)
  91. #define lround(x) __TGMATH_REAL(x, lround)
  92. #define nearbyint(x) __TGMATH_REAL(x, nearbyint)
  93. #define nextafter(x,y) __TGMATH_REAL_2(x, y, nextafter)
  94. #define nexttoward(x,y) __TGMATH_REAL_2(x, y, nexttoward)
  95. #define remainder(x,y) __TGMATH_REAL_2(x, y, remainder)
  96. #define remquo(x,y,z) __TGMATH_REAL_3(x, y, z, remquo)
  97. #define rint(x) __TGMATH_REAL(x, rint)
  98. #define round(x) __TGMATH_REAL(x, round)
  99. #define scalbn(x,y) __TGMATH_REAL_2(x, y, scalbn)
  100. #define scalbln(x,y) __TGMATH_REAL_2(x, y, scalbln)
  101. #define tgamma(x) __TGMATH_REAL(x, tgamma)
  102. #define trunc(x) __TGMATH_REAL(x, trunc)
  103. /* Functions defined in <complex.h> only (7.22p6) */
  104. #define carg(z) __TGMATH_CPLX_ONLY(z, carg)
  105. #define cimag(z) __TGMATH_CPLX_ONLY(z, cimag)
  106. #define conj(z) __TGMATH_CPLX_ONLY(z, conj)
  107. #define cproj(z) __TGMATH_CPLX_ONLY(z, cproj)
  108. #define creal(z) __TGMATH_CPLX_ONLY(z, creal)
  109. #endif /* __cplusplus */
  110. #endif /* _TGMATH_H */