tgmath.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503
  1. /* Copyright (C) 1997-2017 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 Standard: 7.22 Type-generic math <tgmath.h>
  16. */
  17. #ifndef _TGMATH_H
  18. #define _TGMATH_H 1
  19. /* Include the needed headers. */
  20. #include <math.h>
  21. #include <complex.h>
  22. /* Since `complex' is currently not really implemented in most C compilers
  23. and if it is implemented, the implementations differ. This makes it
  24. quite difficult to write a generic implementation of this header. We
  25. do not try this for now and instead concentrate only on GNU CC. Once
  26. we have more information support for other compilers might follow. */
  27. #if __GNUC_PREREQ (2, 7)
  28. # ifdef __NO_LONG_DOUBLE_MATH
  29. # define __tgml(fct) fct
  30. # else
  31. # define __tgml(fct) fct ## l
  32. # endif
  33. /* This is ugly but unless gcc gets appropriate builtins we have to do
  34. something like this. Don't ask how it works. */
  35. /* 1 if 'type' is a floating type, 0 if 'type' is an integer type.
  36. Allows for _Bool. Expands to an integer constant expression. */
  37. # if __GNUC_PREREQ (3, 1)
  38. # define __floating_type(type) \
  39. (__builtin_classify_type ((type) 0) == 8 \
  40. || (__builtin_classify_type ((type) 0) == 9 \
  41. && __builtin_classify_type (__real__ ((type) 0)) == 8))
  42. # else
  43. # define __floating_type(type) (((type) 0.25) && ((type) 0.25 - 1))
  44. # endif
  45. /* The tgmath real type for T, where E is 0 if T is an integer type and
  46. 1 for a floating type. */
  47. # define __tgmath_real_type_sub(T, E) \
  48. __typeof__ (*(0 ? (__typeof__ (0 ? (double *) 0 : (void *) (E))) 0 \
  49. : (__typeof__ (0 ? (T *) 0 : (void *) (!(E)))) 0))
  50. /* The tgmath real type of EXPR. */
  51. # define __tgmath_real_type(expr) \
  52. __tgmath_real_type_sub (__typeof__ ((__typeof__ (expr)) 0), \
  53. __floating_type (__typeof__ (expr)))
  54. /* We have two kinds of generic macros: to support functions which are
  55. only defined on real valued parameters and those which are defined
  56. for complex functions as well. */
  57. # define __TGMATH_UNARY_REAL_ONLY(Val, Fct) \
  58. (__extension__ ((sizeof (Val) == sizeof (double) \
  59. || __builtin_classify_type (Val) != 8) \
  60. ? (__tgmath_real_type (Val)) Fct (Val) \
  61. : (sizeof (Val) == sizeof (float)) \
  62. ? (__tgmath_real_type (Val)) Fct##f (Val) \
  63. : (__tgmath_real_type (Val)) __tgml(Fct) (Val)))
  64. # define __TGMATH_UNARY_REAL_RET_ONLY(Val, RetType, Fct) \
  65. (__extension__ ((sizeof (Val) == sizeof (double) \
  66. || __builtin_classify_type (Val) != 8) \
  67. ? (RetType) Fct (Val) \
  68. : (sizeof (Val) == sizeof (float)) \
  69. ? (RetType) Fct##f (Val) \
  70. : (RetType) __tgml(Fct) (Val)))
  71. # define __TGMATH_BINARY_FIRST_REAL_ONLY(Val1, Val2, Fct) \
  72. (__extension__ ((sizeof (Val1) == sizeof (double) \
  73. || __builtin_classify_type (Val1) != 8) \
  74. ? (__tgmath_real_type (Val1)) Fct (Val1, Val2) \
  75. : (sizeof (Val1) == sizeof (float)) \
  76. ? (__tgmath_real_type (Val1)) Fct##f (Val1, Val2) \
  77. : (__tgmath_real_type (Val1)) __tgml(Fct) (Val1, Val2)))
  78. # define __TGMATH_BINARY_REAL_ONLY(Val1, Val2, Fct) \
  79. (__extension__ (((sizeof (Val1) > sizeof (double) \
  80. || sizeof (Val2) > sizeof (double)) \
  81. && __builtin_classify_type ((Val1) + (Val2)) == 8) \
  82. ? (__typeof ((__tgmath_real_type (Val1)) 0 \
  83. + (__tgmath_real_type (Val2)) 0)) \
  84. __tgml(Fct) (Val1, Val2) \
  85. : (sizeof (Val1) == sizeof (double) \
  86. || sizeof (Val2) == sizeof (double) \
  87. || __builtin_classify_type (Val1) != 8 \
  88. || __builtin_classify_type (Val2) != 8) \
  89. ? (__typeof ((__tgmath_real_type (Val1)) 0 \
  90. + (__tgmath_real_type (Val2)) 0)) \
  91. Fct (Val1, Val2) \
  92. : (__typeof ((__tgmath_real_type (Val1)) 0 \
  93. + (__tgmath_real_type (Val2)) 0)) \
  94. Fct##f (Val1, Val2)))
  95. # define __TGMATH_TERNARY_FIRST_SECOND_REAL_ONLY(Val1, Val2, Val3, Fct) \
  96. (__extension__ (((sizeof (Val1) > sizeof (double) \
  97. || sizeof (Val2) > sizeof (double)) \
  98. && __builtin_classify_type ((Val1) + (Val2)) == 8) \
  99. ? (__typeof ((__tgmath_real_type (Val1)) 0 \
  100. + (__tgmath_real_type (Val2)) 0)) \
  101. __tgml(Fct) (Val1, Val2, Val3) \
  102. : (sizeof (Val1) == sizeof (double) \
  103. || sizeof (Val2) == sizeof (double) \
  104. || __builtin_classify_type (Val1) != 8 \
  105. || __builtin_classify_type (Val2) != 8) \
  106. ? (__typeof ((__tgmath_real_type (Val1)) 0 \
  107. + (__tgmath_real_type (Val2)) 0)) \
  108. Fct (Val1, Val2, Val3) \
  109. : (__typeof ((__tgmath_real_type (Val1)) 0 \
  110. + (__tgmath_real_type (Val2)) 0)) \
  111. Fct##f (Val1, Val2, Val3)))
  112. # define __TGMATH_TERNARY_REAL_ONLY(Val1, Val2, Val3, Fct) \
  113. (__extension__ (((sizeof (Val1) > sizeof (double) \
  114. || sizeof (Val2) > sizeof (double) \
  115. || sizeof (Val3) > sizeof (double)) \
  116. && __builtin_classify_type ((Val1) + (Val2) + (Val3)) \
  117. == 8) \
  118. ? (__typeof ((__tgmath_real_type (Val1)) 0 \
  119. + (__tgmath_real_type (Val2)) 0 \
  120. + (__tgmath_real_type (Val3)) 0)) \
  121. __tgml(Fct) (Val1, Val2, Val3) \
  122. : (sizeof (Val1) == sizeof (double) \
  123. || sizeof (Val2) == sizeof (double) \
  124. || sizeof (Val3) == sizeof (double) \
  125. || __builtin_classify_type (Val1) != 8 \
  126. || __builtin_classify_type (Val2) != 8 \
  127. || __builtin_classify_type (Val3) != 8) \
  128. ? (__typeof ((__tgmath_real_type (Val1)) 0 \
  129. + (__tgmath_real_type (Val2)) 0 \
  130. + (__tgmath_real_type (Val3)) 0)) \
  131. Fct (Val1, Val2, Val3) \
  132. : (__typeof ((__tgmath_real_type (Val1)) 0 \
  133. + (__tgmath_real_type (Val2)) 0 \
  134. + (__tgmath_real_type (Val3)) 0)) \
  135. Fct##f (Val1, Val2, Val3)))
  136. # define __TGMATH_TERNARY_FIRST_REAL_RET_ONLY(Val1, Val2, Val3, RetType, Fct) \
  137. (__extension__ ((sizeof (Val1) == sizeof (double) \
  138. || __builtin_classify_type (Val1) != 8) \
  139. ? (RetType) Fct (Val1, Val2, Val3) \
  140. : (sizeof (Val1) == sizeof (float)) \
  141. ? (RetType) Fct##f (Val1, Val2, Val3) \
  142. : (RetType) __tgml(Fct) (Val1, Val2, Val3)))
  143. /* XXX This definition has to be changed as soon as the compiler understands
  144. the imaginary keyword. */
  145. # define __TGMATH_UNARY_REAL_IMAG(Val, Fct, Cfct) \
  146. (__extension__ ((sizeof (__real__ (Val)) == sizeof (double) \
  147. || __builtin_classify_type (__real__ (Val)) != 8) \
  148. ? ((sizeof (__real__ (Val)) == sizeof (Val)) \
  149. ? (__tgmath_real_type (Val)) Fct (Val) \
  150. : (__tgmath_real_type (Val)) Cfct (Val)) \
  151. : (sizeof (__real__ (Val)) == sizeof (float)) \
  152. ? ((sizeof (__real__ (Val)) == sizeof (Val)) \
  153. ? (__tgmath_real_type (Val)) Fct##f (Val) \
  154. : (__tgmath_real_type (Val)) Cfct##f (Val)) \
  155. : ((sizeof (__real__ (Val)) == sizeof (Val)) \
  156. ? (__tgmath_real_type (Val)) __tgml(Fct) (Val) \
  157. : (__tgmath_real_type (Val)) __tgml(Cfct) (Val))))
  158. # define __TGMATH_UNARY_IMAG(Val, Cfct) \
  159. (__extension__ ((sizeof (__real__ (Val)) == sizeof (double) \
  160. || __builtin_classify_type (__real__ (Val)) != 8) \
  161. ? (__typeof__ ((__tgmath_real_type (Val)) 0 \
  162. + _Complex_I)) Cfct (Val) \
  163. : (sizeof (__real__ (Val)) == sizeof (float)) \
  164. ? (__typeof__ ((__tgmath_real_type (Val)) 0 \
  165. + _Complex_I)) Cfct##f (Val) \
  166. : (__typeof__ ((__tgmath_real_type (Val)) 0 \
  167. + _Complex_I)) __tgml(Cfct) (Val)))
  168. /* XXX This definition has to be changed as soon as the compiler understands
  169. the imaginary keyword. */
  170. # define __TGMATH_UNARY_REAL_IMAG_RET_REAL(Val, Fct, Cfct) \
  171. (__extension__ ((sizeof (__real__ (Val)) == sizeof (double) \
  172. || __builtin_classify_type (__real__ (Val)) != 8) \
  173. ? ((sizeof (__real__ (Val)) == sizeof (Val)) \
  174. ? (__typeof__ (__real__ (__tgmath_real_type (Val)) 0))\
  175. Fct (Val) \
  176. : (__typeof__ (__real__ (__tgmath_real_type (Val)) 0))\
  177. Cfct (Val)) \
  178. : (sizeof (__real__ (Val)) == sizeof (float)) \
  179. ? ((sizeof (__real__ (Val)) == sizeof (Val)) \
  180. ? (__typeof__ (__real__ (__tgmath_real_type (Val)) 0))\
  181. Fct##f (Val) \
  182. : (__typeof__ (__real__ (__tgmath_real_type (Val)) 0))\
  183. Cfct##f (Val)) \
  184. : ((sizeof (__real__ (Val)) == sizeof (Val)) \
  185. ? (__typeof__ (__real__ (__tgmath_real_type (Val)) 0))\
  186. __tgml(Fct) (Val) \
  187. : (__typeof__ (__real__ (__tgmath_real_type (Val)) 0))\
  188. __tgml(Cfct) (Val))))
  189. /* XXX This definition has to be changed as soon as the compiler understands
  190. the imaginary keyword. */
  191. # define __TGMATH_BINARY_REAL_IMAG(Val1, Val2, Fct, Cfct) \
  192. (__extension__ (((sizeof (__real__ (Val1)) > sizeof (double) \
  193. || sizeof (__real__ (Val2)) > sizeof (double)) \
  194. && __builtin_classify_type (__real__ (Val1) \
  195. + __real__ (Val2)) == 8) \
  196. ? ((sizeof (__real__ (Val1)) == sizeof (Val1) \
  197. && sizeof (__real__ (Val2)) == sizeof (Val2)) \
  198. ? (__typeof ((__tgmath_real_type (Val1)) 0 \
  199. + (__tgmath_real_type (Val2)) 0)) \
  200. __tgml(Fct) (Val1, Val2) \
  201. : (__typeof ((__tgmath_real_type (Val1)) 0 \
  202. + (__tgmath_real_type (Val2)) 0)) \
  203. __tgml(Cfct) (Val1, Val2)) \
  204. : (sizeof (__real__ (Val1)) == sizeof (double) \
  205. || sizeof (__real__ (Val2)) == sizeof (double) \
  206. || __builtin_classify_type (__real__ (Val1)) != 8 \
  207. || __builtin_classify_type (__real__ (Val2)) != 8) \
  208. ? ((sizeof (__real__ (Val1)) == sizeof (Val1) \
  209. && sizeof (__real__ (Val2)) == sizeof (Val2)) \
  210. ? (__typeof ((__tgmath_real_type (Val1)) 0 \
  211. + (__tgmath_real_type (Val2)) 0)) \
  212. Fct (Val1, Val2) \
  213. : (__typeof ((__tgmath_real_type (Val1)) 0 \
  214. + (__tgmath_real_type (Val2)) 0)) \
  215. Cfct (Val1, Val2)) \
  216. : ((sizeof (__real__ (Val1)) == sizeof (Val1) \
  217. && sizeof (__real__ (Val2)) == sizeof (Val2)) \
  218. ? (__typeof ((__tgmath_real_type (Val1)) 0 \
  219. + (__tgmath_real_type (Val2)) 0)) \
  220. Fct##f (Val1, Val2) \
  221. : (__typeof ((__tgmath_real_type (Val1)) 0 \
  222. + (__tgmath_real_type (Val2)) 0)) \
  223. Cfct##f (Val1, Val2))))
  224. #else
  225. # error "Unsupported compiler; you cannot use <tgmath.h>"
  226. #endif
  227. /* Unary functions defined for real and complex values. */
  228. /* Trigonometric functions. */
  229. /* Arc cosine of X. */
  230. #define acos(Val) __TGMATH_UNARY_REAL_IMAG (Val, acos, cacos)
  231. /* Arc sine of X. */
  232. #define asin(Val) __TGMATH_UNARY_REAL_IMAG (Val, asin, casin)
  233. /* Arc tangent of X. */
  234. #define atan(Val) __TGMATH_UNARY_REAL_IMAG (Val, atan, catan)
  235. /* Arc tangent of Y/X. */
  236. #define atan2(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, atan2)
  237. /* Cosine of X. */
  238. #define cos(Val) __TGMATH_UNARY_REAL_IMAG (Val, cos, ccos)
  239. /* Sine of X. */
  240. #define sin(Val) __TGMATH_UNARY_REAL_IMAG (Val, sin, csin)
  241. /* Tangent of X. */
  242. #define tan(Val) __TGMATH_UNARY_REAL_IMAG (Val, tan, ctan)
  243. /* Hyperbolic functions. */
  244. /* Hyperbolic arc cosine of X. */
  245. #define acosh(Val) __TGMATH_UNARY_REAL_IMAG (Val, acosh, cacosh)
  246. /* Hyperbolic arc sine of X. */
  247. #define asinh(Val) __TGMATH_UNARY_REAL_IMAG (Val, asinh, casinh)
  248. /* Hyperbolic arc tangent of X. */
  249. #define atanh(Val) __TGMATH_UNARY_REAL_IMAG (Val, atanh, catanh)
  250. /* Hyperbolic cosine of X. */
  251. #define cosh(Val) __TGMATH_UNARY_REAL_IMAG (Val, cosh, ccosh)
  252. /* Hyperbolic sine of X. */
  253. #define sinh(Val) __TGMATH_UNARY_REAL_IMAG (Val, sinh, csinh)
  254. /* Hyperbolic tangent of X. */
  255. #define tanh(Val) __TGMATH_UNARY_REAL_IMAG (Val, tanh, ctanh)
  256. /* Exponential and logarithmic functions. */
  257. /* Exponential function of X. */
  258. #define exp(Val) __TGMATH_UNARY_REAL_IMAG (Val, exp, cexp)
  259. /* Break VALUE into a normalized fraction and an integral power of 2. */
  260. #define frexp(Val1, Val2) __TGMATH_BINARY_FIRST_REAL_ONLY (Val1, Val2, frexp)
  261. /* X times (two to the EXP power). */
  262. #define ldexp(Val1, Val2) __TGMATH_BINARY_FIRST_REAL_ONLY (Val1, Val2, ldexp)
  263. /* Natural logarithm of X. */
  264. #define log(Val) __TGMATH_UNARY_REAL_IMAG (Val, log, clog)
  265. /* Base-ten logarithm of X. */
  266. #ifdef __USE_GNU
  267. # define log10(Val) __TGMATH_UNARY_REAL_IMAG (Val, log10, __clog10)
  268. #else
  269. # define log10(Val) __TGMATH_UNARY_REAL_ONLY (Val, log10)
  270. #endif
  271. /* Return exp(X) - 1. */
  272. #define expm1(Val) __TGMATH_UNARY_REAL_ONLY (Val, expm1)
  273. /* Return log(1 + X). */
  274. #define log1p(Val) __TGMATH_UNARY_REAL_ONLY (Val, log1p)
  275. /* Return the base 2 signed integral exponent of X. */
  276. #define logb(Val) __TGMATH_UNARY_REAL_ONLY (Val, logb)
  277. /* Compute base-2 exponential of X. */
  278. #define exp2(Val) __TGMATH_UNARY_REAL_ONLY (Val, exp2)
  279. /* Compute base-2 logarithm of X. */
  280. #define log2(Val) __TGMATH_UNARY_REAL_ONLY (Val, log2)
  281. /* Power functions. */
  282. /* Return X to the Y power. */
  283. #define pow(Val1, Val2) __TGMATH_BINARY_REAL_IMAG (Val1, Val2, pow, cpow)
  284. /* Return the square root of X. */
  285. #define sqrt(Val) __TGMATH_UNARY_REAL_IMAG (Val, sqrt, csqrt)
  286. /* Return `sqrt(X*X + Y*Y)'. */
  287. #define hypot(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, hypot)
  288. /* Return the cube root of X. */
  289. #define cbrt(Val) __TGMATH_UNARY_REAL_ONLY (Val, cbrt)
  290. /* Nearest integer, absolute value, and remainder functions. */
  291. /* Smallest integral value not less than X. */
  292. #define ceil(Val) __TGMATH_UNARY_REAL_ONLY (Val, ceil)
  293. /* Absolute value of X. */
  294. #define fabs(Val) __TGMATH_UNARY_REAL_IMAG_RET_REAL (Val, fabs, cabs)
  295. /* Largest integer not greater than X. */
  296. #define floor(Val) __TGMATH_UNARY_REAL_ONLY (Val, floor)
  297. /* Floating-point modulo remainder of X/Y. */
  298. #define fmod(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, fmod)
  299. /* Round X to integral valuein floating-point format using current
  300. rounding direction, but do not raise inexact exception. */
  301. #define nearbyint(Val) __TGMATH_UNARY_REAL_ONLY (Val, nearbyint)
  302. /* Round X to nearest integral value, rounding halfway cases away from
  303. zero. */
  304. #define round(Val) __TGMATH_UNARY_REAL_ONLY (Val, round)
  305. /* Round X to the integral value in floating-point format nearest but
  306. not larger in magnitude. */
  307. #define trunc(Val) __TGMATH_UNARY_REAL_ONLY (Val, trunc)
  308. /* Compute remainder of X and Y and put in *QUO a value with sign of x/y
  309. and magnitude congruent `mod 2^n' to the magnitude of the integral
  310. quotient x/y, with n >= 3. */
  311. #define remquo(Val1, Val2, Val3) \
  312. __TGMATH_TERNARY_FIRST_SECOND_REAL_ONLY (Val1, Val2, Val3, remquo)
  313. /* Round X to nearest integral value according to current rounding
  314. direction. */
  315. #define lrint(Val) __TGMATH_UNARY_REAL_RET_ONLY (Val, long int, lrint)
  316. #define llrint(Val) __TGMATH_UNARY_REAL_RET_ONLY (Val, long long int, llrint)
  317. /* Round X to nearest integral value, rounding halfway cases away from
  318. zero. */
  319. #define lround(Val) __TGMATH_UNARY_REAL_RET_ONLY (Val, long int, lround)
  320. #define llround(Val) __TGMATH_UNARY_REAL_RET_ONLY (Val, long long int, llround)
  321. /* Return X with its signed changed to Y's. */
  322. #define copysign(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, copysign)
  323. /* Error and gamma functions. */
  324. #define erf(Val) __TGMATH_UNARY_REAL_ONLY (Val, erf)
  325. #define erfc(Val) __TGMATH_UNARY_REAL_ONLY (Val, erfc)
  326. #define tgamma(Val) __TGMATH_UNARY_REAL_ONLY (Val, tgamma)
  327. #define lgamma(Val) __TGMATH_UNARY_REAL_ONLY (Val, lgamma)
  328. /* Return the integer nearest X in the direction of the
  329. prevailing rounding mode. */
  330. #define rint(Val) __TGMATH_UNARY_REAL_ONLY (Val, rint)
  331. #if __GLIBC_USE (IEC_60559_BFP_EXT)
  332. /* Return X - epsilon. */
  333. # define nextdown(Val) __TGMATH_UNARY_REAL_ONLY (Val, nextdown)
  334. /* Return X + epsilon. */
  335. # define nextup(Val) __TGMATH_UNARY_REAL_ONLY (Val, nextup)
  336. #endif
  337. /* Return X + epsilon if X < Y, X - epsilon if X > Y. */
  338. #define nextafter(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, nextafter)
  339. #define nexttoward(Val1, Val2) \
  340. __TGMATH_BINARY_FIRST_REAL_ONLY (Val1, Val2, nexttoward)
  341. /* Return the remainder of integer divison X / Y with infinite precision. */
  342. #define remainder(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, remainder)
  343. /* Return X times (2 to the Nth power). */
  344. #ifdef __USE_MISC
  345. # define scalb(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, scalb)
  346. #endif
  347. /* Return X times (2 to the Nth power). */
  348. #define scalbn(Val1, Val2) __TGMATH_BINARY_FIRST_REAL_ONLY (Val1, Val2, scalbn)
  349. /* Return X times (2 to the Nth power). */
  350. #define scalbln(Val1, Val2) \
  351. __TGMATH_BINARY_FIRST_REAL_ONLY (Val1, Val2, scalbln)
  352. /* Return the binary exponent of X, which must be nonzero. */
  353. #define ilogb(Val) __TGMATH_UNARY_REAL_RET_ONLY (Val, int, ilogb)
  354. /* Return positive difference between X and Y. */
  355. #define fdim(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, fdim)
  356. /* Return maximum numeric value from X and Y. */
  357. #define fmax(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, fmax)
  358. /* Return minimum numeric value from X and Y. */
  359. #define fmin(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, fmin)
  360. /* Multiply-add function computed as a ternary operation. */
  361. #define fma(Val1, Val2, Val3) \
  362. __TGMATH_TERNARY_REAL_ONLY (Val1, Val2, Val3, fma)
  363. #if __GLIBC_USE (IEC_60559_BFP_EXT)
  364. /* Round X to nearest integer value, rounding halfway cases to even. */
  365. # define roundeven(Val) __TGMATH_UNARY_REAL_ONLY (Val, roundeven)
  366. # define fromfp(Val1, Val2, Val3) \
  367. __TGMATH_TERNARY_FIRST_REAL_RET_ONLY (Val1, Val2, Val3, __intmax_t, fromfp)
  368. # define ufromfp(Val1, Val2, Val3) \
  369. __TGMATH_TERNARY_FIRST_REAL_RET_ONLY (Val1, Val2, Val3, __uintmax_t, ufromfp)
  370. # define fromfpx(Val1, Val2, Val3) \
  371. __TGMATH_TERNARY_FIRST_REAL_RET_ONLY (Val1, Val2, Val3, __intmax_t, fromfpx)
  372. # define ufromfpx(Val1, Val2, Val3) \
  373. __TGMATH_TERNARY_FIRST_REAL_RET_ONLY (Val1, Val2, Val3, __uintmax_t, ufromfpx)
  374. /* Like ilogb, but returning long int. */
  375. # define llogb(Val) __TGMATH_UNARY_REAL_RET_ONLY (Val, long int, llogb)
  376. /* Return value with maximum magnitude. */
  377. # define fmaxmag(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, fmaxmag)
  378. /* Return value with minimum magnitude. */
  379. # define fminmag(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, fminmag)
  380. /* Total order operation. */
  381. # define totalorder(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, \
  382. totalorder)
  383. /* Total order operation on absolute values. */
  384. # define totalordermag(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, \
  385. totalordermag)
  386. #endif
  387. /* Absolute value, conjugates, and projection. */
  388. /* Argument value of Z. */
  389. #define carg(Val) __TGMATH_UNARY_REAL_IMAG_RET_REAL (Val, carg, carg)
  390. /* Complex conjugate of Z. */
  391. #define conj(Val) __TGMATH_UNARY_IMAG (Val, conj)
  392. /* Projection of Z onto the Riemann sphere. */
  393. #define cproj(Val) __TGMATH_UNARY_IMAG (Val, cproj)
  394. /* Decomposing complex values. */
  395. /* Imaginary part of Z. */
  396. #define cimag(Val) __TGMATH_UNARY_REAL_IMAG_RET_REAL (Val, cimag, cimag)
  397. /* Real part of Z. */
  398. #define creal(Val) __TGMATH_UNARY_REAL_IMAG_RET_REAL (Val, creal, creal)
  399. #endif /* tgmath.h */