tgmath.h 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909
  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 Standard: 7.22 Type-generic math <tgmath.h>
  16. */
  17. #ifndef _TGMATH_H
  18. #define _TGMATH_H 1
  19. #define __GLIBC_INTERNAL_STARTING_HEADER_IMPLEMENTATION
  20. #include <bits/libc-header-start.h>
  21. /* Include the needed headers. */
  22. #include <bits/floatn.h>
  23. #include <math.h>
  24. #include <complex.h>
  25. /* There are two variant implementations of type-generic macros in
  26. this file: one for GCC 8 and later, using __builtin_tgmath and
  27. where each macro expands each of its arguments only once, and one
  28. for older GCC, using other compiler extensions but with macros
  29. expanding their arguments many times (so resulting in exponential
  30. blowup of the size of expansions when calls to such macros are
  31. nested inside arguments to such macros). */
  32. #define __HAVE_BUILTIN_TGMATH __GNUC_PREREQ (8, 0)
  33. #if __GNUC_PREREQ (2, 7)
  34. /* Certain cases of narrowing macros only need to call a single
  35. function so cannot use __builtin_tgmath and do not need any
  36. complicated logic. */
  37. # if __HAVE_FLOAT128X
  38. # error "Unsupported _Float128x type for <tgmath.h>."
  39. # endif
  40. # if ((__HAVE_FLOAT64X && !__HAVE_FLOAT128) \
  41. || (__HAVE_FLOAT128 && !__HAVE_FLOAT64X))
  42. # error "Unsupported combination of types for <tgmath.h>."
  43. # endif
  44. # define __TGMATH_2_NARROW_D(F, X, Y) \
  45. (F ## l (X, Y))
  46. # define __TGMATH_2_NARROW_F64X(F, X, Y) \
  47. (F ## f128 (X, Y))
  48. # if !__HAVE_FLOAT128
  49. # define __TGMATH_2_NARROW_F32X(F, X, Y) \
  50. (F ## f64 (X, Y))
  51. # endif
  52. # if __HAVE_BUILTIN_TGMATH
  53. # if __HAVE_FLOAT16 && __GLIBC_USE (IEC_60559_TYPES_EXT)
  54. # define __TG_F16_ARG(X) X ## f16,
  55. # else
  56. # define __TG_F16_ARG(X)
  57. # endif
  58. # if __HAVE_FLOAT32 && __GLIBC_USE (IEC_60559_TYPES_EXT)
  59. # define __TG_F32_ARG(X) X ## f32,
  60. # else
  61. # define __TG_F32_ARG(X)
  62. # endif
  63. # if __HAVE_FLOAT64 && __GLIBC_USE (IEC_60559_TYPES_EXT)
  64. # define __TG_F64_ARG(X) X ## f64,
  65. # else
  66. # define __TG_F64_ARG(X)
  67. # endif
  68. # if __HAVE_FLOAT128 && __GLIBC_USE (IEC_60559_TYPES_EXT)
  69. # define __TG_F128_ARG(X) X ## f128,
  70. # else
  71. # define __TG_F128_ARG(X)
  72. # endif
  73. # if __HAVE_FLOAT32X && __GLIBC_USE (IEC_60559_TYPES_EXT)
  74. # define __TG_F32X_ARG(X) X ## f32x,
  75. # else
  76. # define __TG_F32X_ARG(X)
  77. # endif
  78. # if __HAVE_FLOAT64X && __GLIBC_USE (IEC_60559_TYPES_EXT)
  79. # define __TG_F64X_ARG(X) X ## f64x,
  80. # else
  81. # define __TG_F64X_ARG(X)
  82. # endif
  83. # if __HAVE_FLOAT128X && __GLIBC_USE (IEC_60559_TYPES_EXT)
  84. # define __TG_F128X_ARG(X) X ## f128x,
  85. # else
  86. # define __TG_F128X_ARG(X)
  87. # endif
  88. # define __TGMATH_FUNCS(X) X ## f, X, X ## l, \
  89. __TG_F16_ARG (X) __TG_F32_ARG (X) __TG_F64_ARG (X) __TG_F128_ARG (X) \
  90. __TG_F32X_ARG (X) __TG_F64X_ARG (X) __TG_F128X_ARG (X)
  91. # define __TGMATH_RCFUNCS(F, C) __TGMATH_FUNCS (F) __TGMATH_FUNCS (C)
  92. # define __TGMATH_1(F, X) __builtin_tgmath (__TGMATH_FUNCS (F) (X))
  93. # define __TGMATH_2(F, X, Y) __builtin_tgmath (__TGMATH_FUNCS (F) (X), (Y))
  94. # define __TGMATH_2STD(F, X, Y) __builtin_tgmath (F ## f, F, F ## l, (X), (Y))
  95. # define __TGMATH_3(F, X, Y, Z) __builtin_tgmath (__TGMATH_FUNCS (F) \
  96. (X), (Y), (Z))
  97. # define __TGMATH_1C(F, C, X) __builtin_tgmath (__TGMATH_RCFUNCS (F, C) (X))
  98. # define __TGMATH_2C(F, C, X, Y) __builtin_tgmath (__TGMATH_RCFUNCS (F, C) \
  99. (X), (Y))
  100. # define __TGMATH_NARROW_FUNCS_F(X) X, X ## l,
  101. # define __TGMATH_NARROW_FUNCS_F16(X) \
  102. __TG_F32_ARG (X) __TG_F64_ARG (X) __TG_F128_ARG (X) \
  103. __TG_F32X_ARG (X) __TG_F64X_ARG (X) __TG_F128X_ARG (X)
  104. # define __TGMATH_NARROW_FUNCS_F32(X) \
  105. __TG_F64_ARG (X) __TG_F128_ARG (X) \
  106. __TG_F32X_ARG (X) __TG_F64X_ARG (X) __TG_F128X_ARG (X)
  107. # define __TGMATH_NARROW_FUNCS_F64(X) \
  108. __TG_F128_ARG (X) \
  109. __TG_F64X_ARG (X) __TG_F128X_ARG (X)
  110. # define __TGMATH_NARROW_FUNCS_F32X(X) \
  111. __TG_F64X_ARG (X) __TG_F128X_ARG (X) \
  112. __TG_F64_ARG (X) __TG_F128_ARG (X)
  113. # define __TGMATH_2_NARROW_F(F, X, Y) \
  114. __builtin_tgmath (__TGMATH_NARROW_FUNCS_F (F) (X), (Y))
  115. # define __TGMATH_2_NARROW_F16(F, X, Y) \
  116. __builtin_tgmath (__TGMATH_NARROW_FUNCS_F16 (F) (X), (Y))
  117. # define __TGMATH_2_NARROW_F32(F, X, Y) \
  118. __builtin_tgmath (__TGMATH_NARROW_FUNCS_F32 (F) (X), (Y))
  119. # define __TGMATH_2_NARROW_F64(F, X, Y) \
  120. __builtin_tgmath (__TGMATH_NARROW_FUNCS_F64 (F) (X), (Y))
  121. # if __HAVE_FLOAT128
  122. # define __TGMATH_2_NARROW_F32X(F, X, Y) \
  123. __builtin_tgmath (__TGMATH_NARROW_FUNCS_F32X (F) (X), (Y))
  124. # endif
  125. # else /* !__HAVE_BUILTIN_TGMATH. */
  126. # ifdef __NO_LONG_DOUBLE_MATH
  127. # define __tgml(fct) fct
  128. # else
  129. # define __tgml(fct) fct ## l
  130. # endif
  131. /* __floating_type expands to 1 if TYPE is a floating type (including
  132. complex floating types), 0 if TYPE is an integer type (including
  133. complex integer types). __real_integer_type expands to 1 if TYPE
  134. is a real integer type. __complex_integer_type expands to 1 if
  135. TYPE is a complex integer type. All these macros expand to integer
  136. constant expressions. All these macros can assume their argument
  137. has an arithmetic type (not vector, decimal floating-point or
  138. fixed-point), valid to pass to tgmath.h macros. */
  139. # if __GNUC_PREREQ (3, 1)
  140. /* __builtin_classify_type expands to an integer constant expression
  141. in GCC 3.1 and later. Default conversions applied to the argument
  142. of __builtin_classify_type mean it always returns 1 for real
  143. integer types rather than ever returning different values for
  144. character, boolean or enumerated types. */
  145. # define __floating_type(type) \
  146. (__builtin_classify_type (__real__ ((type) 0)) == 8)
  147. # define __real_integer_type(type) \
  148. (__builtin_classify_type ((type) 0) == 1)
  149. # define __complex_integer_type(type) \
  150. (__builtin_classify_type ((type) 0) == 9 \
  151. && __builtin_classify_type (__real__ ((type) 0)) == 1)
  152. # else
  153. /* GCC versions predating __builtin_classify_type are also looser on
  154. what counts as an integer constant expression. */
  155. # define __floating_type(type) (((type) 1.25) != 1)
  156. # define __real_integer_type(type) (((type) (1.25 + _Complex_I)) == 1)
  157. # define __complex_integer_type(type) \
  158. (((type) (1.25 + _Complex_I)) == (1 + _Complex_I))
  159. # endif
  160. /* Whether an expression (of arithmetic type) has a real type. */
  161. # define __expr_is_real(E) (__builtin_classify_type (E) != 9)
  162. /* The tgmath real type for T, where E is 0 if T is an integer type
  163. and 1 for a floating type. If T has a complex type, it is
  164. unspecified whether the return type is real or complex (but it has
  165. the correct corresponding real type). */
  166. # define __tgmath_real_type_sub(T, E) \
  167. __typeof__ (*(0 ? (__typeof__ (0 ? (double *) 0 : (void *) (E))) 0 \
  168. : (__typeof__ (0 ? (T *) 0 : (void *) (!(E)))) 0))
  169. /* The tgmath real type of EXPR. */
  170. # define __tgmath_real_type(expr) \
  171. __tgmath_real_type_sub (__typeof__ ((__typeof__ (+(expr))) 0), \
  172. __floating_type (__typeof__ (+(expr))))
  173. /* The tgmath complex type for T, where E1 is 1 if T has a floating
  174. type and 0 otherwise, E2 is 1 if T has a real integer type and 0
  175. otherwise, and E3 is 1 if T has a complex type and 0 otherwise. */
  176. # define __tgmath_complex_type_sub(T, E1, E2, E3) \
  177. __typeof__ (*(0 \
  178. ? (__typeof__ (0 ? (T *) 0 : (void *) (!(E1)))) 0 \
  179. : (__typeof__ (0 \
  180. ? (__typeof__ (0 \
  181. ? (double *) 0 \
  182. : (void *) (!(E2)))) 0 \
  183. : (__typeof__ (0 \
  184. ? (_Complex double *) 0 \
  185. : (void *) (!(E3)))) 0)) 0))
  186. /* The tgmath complex type of EXPR. */
  187. # define __tgmath_complex_type(expr) \
  188. __tgmath_complex_type_sub (__typeof__ ((__typeof__ (+(expr))) 0), \
  189. __floating_type (__typeof__ (+(expr))), \
  190. __real_integer_type (__typeof__ (+(expr))), \
  191. __complex_integer_type (__typeof__ (+(expr))))
  192. # if (__HAVE_DISTINCT_FLOAT16 \
  193. || __HAVE_DISTINCT_FLOAT32 \
  194. || __HAVE_DISTINCT_FLOAT64 \
  195. || __HAVE_DISTINCT_FLOAT32X \
  196. || __HAVE_DISTINCT_FLOAT64X \
  197. || __HAVE_DISTINCT_FLOAT128X)
  198. # error "Unsupported _FloatN or _FloatNx types for <tgmath.h>."
  199. # endif
  200. /* Expand to text that checks if ARG_COMB has type _Float128, and if
  201. so calls the appropriately suffixed FCT (which may include a cast),
  202. or FCT and CFCT for complex functions, with arguments ARG_CALL. */
  203. # if __HAVE_DISTINCT_FLOAT128 && __GLIBC_USE (IEC_60559_TYPES_EXT)
  204. # if (!__HAVE_FLOAT64X \
  205. || __HAVE_FLOAT64X_LONG_DOUBLE \
  206. || !__HAVE_FLOATN_NOT_TYPEDEF)
  207. # define __TGMATH_F128(arg_comb, fct, arg_call) \
  208. __builtin_types_compatible_p (__typeof (+(arg_comb)), _Float128) \
  209. ? fct ## f128 arg_call :
  210. # define __TGMATH_CF128(arg_comb, fct, cfct, arg_call) \
  211. __builtin_types_compatible_p (__typeof (+__real__ (arg_comb)), _Float128) \
  212. ? (__expr_is_real (arg_comb) \
  213. ? fct ## f128 arg_call \
  214. : cfct ## f128 arg_call) :
  215. # else
  216. /* _Float64x is a distinct type at the C language level, which must be
  217. handled like _Float128. */
  218. # define __TGMATH_F128(arg_comb, fct, arg_call) \
  219. (__builtin_types_compatible_p (__typeof (+(arg_comb)), _Float128) \
  220. || __builtin_types_compatible_p (__typeof (+(arg_comb)), _Float64x)) \
  221. ? fct ## f128 arg_call :
  222. # define __TGMATH_CF128(arg_comb, fct, cfct, arg_call) \
  223. (__builtin_types_compatible_p (__typeof (+__real__ (arg_comb)), _Float128) \
  224. || __builtin_types_compatible_p (__typeof (+__real__ (arg_comb)), \
  225. _Float64x)) \
  226. ? (__expr_is_real (arg_comb) \
  227. ? fct ## f128 arg_call \
  228. : cfct ## f128 arg_call) :
  229. # endif
  230. # else
  231. # define __TGMATH_F128(arg_comb, fct, arg_call) /* Nothing. */
  232. # define __TGMATH_CF128(arg_comb, fct, cfct, arg_call) /* Nothing. */
  233. # endif
  234. # endif /* !__HAVE_BUILTIN_TGMATH. */
  235. /* We have two kinds of generic macros: to support functions which are
  236. only defined on real valued parameters and those which are defined
  237. for complex functions as well. */
  238. # if __HAVE_BUILTIN_TGMATH
  239. # define __TGMATH_UNARY_REAL_ONLY(Val, Fct) __TGMATH_1 (Fct, (Val))
  240. # define __TGMATH_UNARY_REAL_RET_ONLY(Val, Fct) __TGMATH_1 (Fct, (Val))
  241. # define __TGMATH_BINARY_FIRST_REAL_ONLY(Val1, Val2, Fct) \
  242. __TGMATH_2 (Fct, (Val1), (Val2))
  243. # define __TGMATH_BINARY_FIRST_REAL_STD_ONLY(Val1, Val2, Fct) \
  244. __TGMATH_2STD (Fct, (Val1), (Val2))
  245. # define __TGMATH_BINARY_REAL_ONLY(Val1, Val2, Fct) \
  246. __TGMATH_2 (Fct, (Val1), (Val2))
  247. # define __TGMATH_BINARY_REAL_STD_ONLY(Val1, Val2, Fct) \
  248. __TGMATH_2STD (Fct, (Val1), (Val2))
  249. # define __TGMATH_TERNARY_FIRST_SECOND_REAL_ONLY(Val1, Val2, Val3, Fct) \
  250. __TGMATH_3 (Fct, (Val1), (Val2), (Val3))
  251. # define __TGMATH_TERNARY_REAL_ONLY(Val1, Val2, Val3, Fct) \
  252. __TGMATH_3 (Fct, (Val1), (Val2), (Val3))
  253. # define __TGMATH_TERNARY_FIRST_REAL_RET_ONLY(Val1, Val2, Val3, Fct) \
  254. __TGMATH_3 (Fct, (Val1), (Val2), (Val3))
  255. # define __TGMATH_UNARY_REAL_IMAG(Val, Fct, Cfct) \
  256. __TGMATH_1C (Fct, Cfct, (Val))
  257. # define __TGMATH_UNARY_IMAG(Val, Cfct) __TGMATH_1 (Cfct, (Val))
  258. # define __TGMATH_UNARY_REAL_IMAG_RET_REAL(Val, Fct, Cfct) \
  259. __TGMATH_1C (Fct, Cfct, (Val))
  260. # define __TGMATH_UNARY_REAL_IMAG_RET_REAL_SAME(Val, Cfct) \
  261. __TGMATH_1 (Cfct, (Val))
  262. # define __TGMATH_BINARY_REAL_IMAG(Val1, Val2, Fct, Cfct) \
  263. __TGMATH_2C (Fct, Cfct, (Val1), (Val2))
  264. # else /* !__HAVE_BUILTIN_TGMATH. */
  265. # define __TGMATH_UNARY_REAL_ONLY(Val, Fct) \
  266. (__extension__ ((sizeof (+(Val)) == sizeof (double) \
  267. || __builtin_classify_type (Val) != 8) \
  268. ? (__tgmath_real_type (Val)) Fct (Val) \
  269. : (sizeof (+(Val)) == sizeof (float)) \
  270. ? (__tgmath_real_type (Val)) Fct##f (Val) \
  271. : __TGMATH_F128 ((Val), (__tgmath_real_type (Val)) Fct, \
  272. (Val)) \
  273. (__tgmath_real_type (Val)) __tgml(Fct) (Val)))
  274. # define __TGMATH_UNARY_REAL_RET_ONLY(Val, Fct) \
  275. (__extension__ ((sizeof (+(Val)) == sizeof (double) \
  276. || __builtin_classify_type (Val) != 8) \
  277. ? Fct (Val) \
  278. : (sizeof (+(Val)) == sizeof (float)) \
  279. ? Fct##f (Val) \
  280. : __TGMATH_F128 ((Val), Fct, (Val)) \
  281. __tgml(Fct) (Val)))
  282. # define __TGMATH_BINARY_FIRST_REAL_ONLY(Val1, Val2, Fct) \
  283. (__extension__ ((sizeof (+(Val1)) == sizeof (double) \
  284. || __builtin_classify_type (Val1) != 8) \
  285. ? (__tgmath_real_type (Val1)) Fct (Val1, Val2) \
  286. : (sizeof (+(Val1)) == sizeof (float)) \
  287. ? (__tgmath_real_type (Val1)) Fct##f (Val1, Val2) \
  288. : __TGMATH_F128 ((Val1), (__tgmath_real_type (Val1)) Fct, \
  289. (Val1, Val2)) \
  290. (__tgmath_real_type (Val1)) __tgml(Fct) (Val1, Val2)))
  291. # define __TGMATH_BINARY_FIRST_REAL_STD_ONLY(Val1, Val2, Fct) \
  292. (__extension__ ((sizeof (+(Val1)) == sizeof (double) \
  293. || __builtin_classify_type (Val1) != 8) \
  294. ? (__tgmath_real_type (Val1)) Fct (Val1, Val2) \
  295. : (sizeof (+(Val1)) == sizeof (float)) \
  296. ? (__tgmath_real_type (Val1)) Fct##f (Val1, Val2) \
  297. : (__tgmath_real_type (Val1)) __tgml(Fct) (Val1, Val2)))
  298. # define __TGMATH_BINARY_REAL_ONLY(Val1, Val2, Fct) \
  299. (__extension__ ((sizeof ((Val1) + (Val2)) > sizeof (double) \
  300. && __builtin_classify_type ((Val1) + (Val2)) == 8) \
  301. ? __TGMATH_F128 ((Val1) + (Val2), \
  302. (__typeof \
  303. ((__tgmath_real_type (Val1)) 0 \
  304. + (__tgmath_real_type (Val2)) 0)) Fct, \
  305. (Val1, Val2)) \
  306. (__typeof ((__tgmath_real_type (Val1)) 0 \
  307. + (__tgmath_real_type (Val2)) 0)) \
  308. __tgml(Fct) (Val1, Val2) \
  309. : (sizeof (+(Val1)) == sizeof (double) \
  310. || sizeof (+(Val2)) == sizeof (double) \
  311. || __builtin_classify_type (Val1) != 8 \
  312. || __builtin_classify_type (Val2) != 8) \
  313. ? (__typeof ((__tgmath_real_type (Val1)) 0 \
  314. + (__tgmath_real_type (Val2)) 0)) \
  315. Fct (Val1, Val2) \
  316. : (__typeof ((__tgmath_real_type (Val1)) 0 \
  317. + (__tgmath_real_type (Val2)) 0)) \
  318. Fct##f (Val1, Val2)))
  319. # define __TGMATH_BINARY_REAL_STD_ONLY(Val1, Val2, Fct) \
  320. (__extension__ ((sizeof ((Val1) + (Val2)) > sizeof (double) \
  321. && __builtin_classify_type ((Val1) + (Val2)) == 8) \
  322. ? (__typeof ((__tgmath_real_type (Val1)) 0 \
  323. + (__tgmath_real_type (Val2)) 0)) \
  324. __tgml(Fct) (Val1, Val2) \
  325. : (sizeof (+(Val1)) == sizeof (double) \
  326. || sizeof (+(Val2)) == sizeof (double) \
  327. || __builtin_classify_type (Val1) != 8 \
  328. || __builtin_classify_type (Val2) != 8) \
  329. ? (__typeof ((__tgmath_real_type (Val1)) 0 \
  330. + (__tgmath_real_type (Val2)) 0)) \
  331. Fct (Val1, Val2) \
  332. : (__typeof ((__tgmath_real_type (Val1)) 0 \
  333. + (__tgmath_real_type (Val2)) 0)) \
  334. Fct##f (Val1, Val2)))
  335. # define __TGMATH_TERNARY_FIRST_SECOND_REAL_ONLY(Val1, Val2, Val3, Fct) \
  336. (__extension__ ((sizeof ((Val1) + (Val2)) > sizeof (double) \
  337. && __builtin_classify_type ((Val1) + (Val2)) == 8) \
  338. ? __TGMATH_F128 ((Val1) + (Val2), \
  339. (__typeof \
  340. ((__tgmath_real_type (Val1)) 0 \
  341. + (__tgmath_real_type (Val2)) 0)) Fct, \
  342. (Val1, Val2, Val3)) \
  343. (__typeof ((__tgmath_real_type (Val1)) 0 \
  344. + (__tgmath_real_type (Val2)) 0)) \
  345. __tgml(Fct) (Val1, Val2, Val3) \
  346. : (sizeof (+(Val1)) == sizeof (double) \
  347. || sizeof (+(Val2)) == sizeof (double) \
  348. || __builtin_classify_type (Val1) != 8 \
  349. || __builtin_classify_type (Val2) != 8) \
  350. ? (__typeof ((__tgmath_real_type (Val1)) 0 \
  351. + (__tgmath_real_type (Val2)) 0)) \
  352. Fct (Val1, Val2, Val3) \
  353. : (__typeof ((__tgmath_real_type (Val1)) 0 \
  354. + (__tgmath_real_type (Val2)) 0)) \
  355. Fct##f (Val1, Val2, Val3)))
  356. # define __TGMATH_TERNARY_REAL_ONLY(Val1, Val2, Val3, Fct) \
  357. (__extension__ ((sizeof ((Val1) + (Val2) + (Val3)) > sizeof (double) \
  358. && __builtin_classify_type ((Val1) + (Val2) + (Val3)) \
  359. == 8) \
  360. ? __TGMATH_F128 ((Val1) + (Val2) + (Val3), \
  361. (__typeof \
  362. ((__tgmath_real_type (Val1)) 0 \
  363. + (__tgmath_real_type (Val2)) 0 \
  364. + (__tgmath_real_type (Val3)) 0)) Fct, \
  365. (Val1, Val2, Val3)) \
  366. (__typeof ((__tgmath_real_type (Val1)) 0 \
  367. + (__tgmath_real_type (Val2)) 0 \
  368. + (__tgmath_real_type (Val3)) 0)) \
  369. __tgml(Fct) (Val1, Val2, Val3) \
  370. : (sizeof (+(Val1)) == sizeof (double) \
  371. || sizeof (+(Val2)) == sizeof (double) \
  372. || sizeof (+(Val3)) == sizeof (double) \
  373. || __builtin_classify_type (Val1) != 8 \
  374. || __builtin_classify_type (Val2) != 8 \
  375. || __builtin_classify_type (Val3) != 8) \
  376. ? (__typeof ((__tgmath_real_type (Val1)) 0 \
  377. + (__tgmath_real_type (Val2)) 0 \
  378. + (__tgmath_real_type (Val3)) 0)) \
  379. Fct (Val1, Val2, Val3) \
  380. : (__typeof ((__tgmath_real_type (Val1)) 0 \
  381. + (__tgmath_real_type (Val2)) 0 \
  382. + (__tgmath_real_type (Val3)) 0)) \
  383. Fct##f (Val1, Val2, Val3)))
  384. # define __TGMATH_TERNARY_FIRST_REAL_RET_ONLY(Val1, Val2, Val3, Fct) \
  385. (__extension__ ((sizeof (+(Val1)) == sizeof (double) \
  386. || __builtin_classify_type (Val1) != 8) \
  387. ? Fct (Val1, Val2, Val3) \
  388. : (sizeof (+(Val1)) == sizeof (float)) \
  389. ? Fct##f (Val1, Val2, Val3) \
  390. : __TGMATH_F128 ((Val1), Fct, (Val1, Val2, Val3)) \
  391. __tgml(Fct) (Val1, Val2, Val3)))
  392. /* XXX This definition has to be changed as soon as the compiler understands
  393. the imaginary keyword. */
  394. # define __TGMATH_UNARY_REAL_IMAG(Val, Fct, Cfct) \
  395. (__extension__ ((sizeof (+__real__ (Val)) == sizeof (double) \
  396. || __builtin_classify_type (__real__ (Val)) != 8) \
  397. ? (__expr_is_real (Val) \
  398. ? (__tgmath_complex_type (Val)) Fct (Val) \
  399. : (__tgmath_complex_type (Val)) Cfct (Val)) \
  400. : (sizeof (+__real__ (Val)) == sizeof (float)) \
  401. ? (__expr_is_real (Val) \
  402. ? (__tgmath_complex_type (Val)) Fct##f (Val) \
  403. : (__tgmath_complex_type (Val)) Cfct##f (Val)) \
  404. : __TGMATH_CF128 ((Val), \
  405. (__tgmath_complex_type (Val)) Fct, \
  406. (__tgmath_complex_type (Val)) Cfct, \
  407. (Val)) \
  408. (__expr_is_real (Val) \
  409. ? (__tgmath_complex_type (Val)) __tgml(Fct) (Val) \
  410. : (__tgmath_complex_type (Val)) __tgml(Cfct) (Val))))
  411. # define __TGMATH_UNARY_IMAG(Val, Cfct) \
  412. (__extension__ ((sizeof (+__real__ (Val)) == sizeof (double) \
  413. || __builtin_classify_type (__real__ (Val)) != 8) \
  414. ? (__typeof__ ((__tgmath_real_type (Val)) 0 \
  415. + _Complex_I)) Cfct (Val) \
  416. : (sizeof (+__real__ (Val)) == sizeof (float)) \
  417. ? (__typeof__ ((__tgmath_real_type (Val)) 0 \
  418. + _Complex_I)) Cfct##f (Val) \
  419. : __TGMATH_F128 (__real__ (Val), \
  420. (__typeof__ \
  421. ((__tgmath_real_type (Val)) 0 \
  422. + _Complex_I)) Cfct, (Val)) \
  423. (__typeof__ ((__tgmath_real_type (Val)) 0 \
  424. + _Complex_I)) __tgml(Cfct) (Val)))
  425. /* XXX This definition has to be changed as soon as the compiler understands
  426. the imaginary keyword. */
  427. # define __TGMATH_UNARY_REAL_IMAG_RET_REAL(Val, Fct, Cfct) \
  428. (__extension__ ((sizeof (+__real__ (Val)) == sizeof (double) \
  429. || __builtin_classify_type (__real__ (Val)) != 8) \
  430. ? (__expr_is_real (Val) \
  431. ? (__typeof__ (__real__ (__tgmath_real_type (Val)) 0))\
  432. Fct (Val) \
  433. : (__typeof__ (__real__ (__tgmath_real_type (Val)) 0))\
  434. Cfct (Val)) \
  435. : (sizeof (+__real__ (Val)) == sizeof (float)) \
  436. ? (__expr_is_real (Val) \
  437. ? (__typeof__ (__real__ (__tgmath_real_type (Val)) 0))\
  438. Fct##f (Val) \
  439. : (__typeof__ (__real__ (__tgmath_real_type (Val)) 0))\
  440. Cfct##f (Val)) \
  441. : __TGMATH_CF128 ((Val), \
  442. (__typeof__ \
  443. (__real__ \
  444. (__tgmath_real_type (Val)) 0)) Fct, \
  445. (__typeof__ \
  446. (__real__ \
  447. (__tgmath_real_type (Val)) 0)) Cfct, \
  448. (Val)) \
  449. (__expr_is_real (Val) \
  450. ? (__typeof__ (__real__ (__tgmath_real_type (Val)) 0)) \
  451. __tgml(Fct) (Val) \
  452. : (__typeof__ (__real__ (__tgmath_real_type (Val)) 0)) \
  453. __tgml(Cfct) (Val))))
  454. # define __TGMATH_UNARY_REAL_IMAG_RET_REAL_SAME(Val, Cfct) \
  455. __TGMATH_UNARY_REAL_IMAG_RET_REAL ((Val), Cfct, Cfct)
  456. /* XXX This definition has to be changed as soon as the compiler understands
  457. the imaginary keyword. */
  458. # define __TGMATH_BINARY_REAL_IMAG(Val1, Val2, Fct, Cfct) \
  459. (__extension__ ((sizeof (__real__ (Val1) \
  460. + __real__ (Val2)) > sizeof (double) \
  461. && __builtin_classify_type (__real__ (Val1) \
  462. + __real__ (Val2)) == 8) \
  463. ? __TGMATH_CF128 ((Val1) + (Val2), \
  464. (__typeof \
  465. ((__tgmath_complex_type (Val1)) 0 \
  466. + (__tgmath_complex_type (Val2)) 0)) \
  467. Fct, \
  468. (__typeof \
  469. ((__tgmath_complex_type (Val1)) 0 \
  470. + (__tgmath_complex_type (Val2)) 0)) \
  471. Cfct, \
  472. (Val1, Val2)) \
  473. (__expr_is_real ((Val1) + (Val2)) \
  474. ? (__typeof ((__tgmath_complex_type (Val1)) 0 \
  475. + (__tgmath_complex_type (Val2)) 0)) \
  476. __tgml(Fct) (Val1, Val2) \
  477. : (__typeof ((__tgmath_complex_type (Val1)) 0 \
  478. + (__tgmath_complex_type (Val2)) 0)) \
  479. __tgml(Cfct) (Val1, Val2)) \
  480. : (sizeof (+__real__ (Val1)) == sizeof (double) \
  481. || sizeof (+__real__ (Val2)) == sizeof (double) \
  482. || __builtin_classify_type (__real__ (Val1)) != 8 \
  483. || __builtin_classify_type (__real__ (Val2)) != 8) \
  484. ? (__expr_is_real ((Val1) + (Val2)) \
  485. ? (__typeof ((__tgmath_complex_type (Val1)) 0 \
  486. + (__tgmath_complex_type (Val2)) 0)) \
  487. Fct (Val1, Val2) \
  488. : (__typeof ((__tgmath_complex_type (Val1)) 0 \
  489. + (__tgmath_complex_type (Val2)) 0)) \
  490. Cfct (Val1, Val2)) \
  491. : (__expr_is_real ((Val1) + (Val2)) \
  492. ? (__typeof ((__tgmath_complex_type (Val1)) 0 \
  493. + (__tgmath_complex_type (Val2)) 0)) \
  494. Fct##f (Val1, Val2) \
  495. : (__typeof ((__tgmath_complex_type (Val1)) 0 \
  496. + (__tgmath_complex_type (Val2)) 0)) \
  497. Cfct##f (Val1, Val2))))
  498. # define __TGMATH_2_NARROW_F(F, X, Y) \
  499. (__extension__ (sizeof ((__tgmath_real_type (X)) 0 \
  500. + (__tgmath_real_type (Y)) 0) > sizeof (double) \
  501. ? F ## l (X, Y) \
  502. : F (X, Y)))
  503. /* In most cases, these narrowing macro definitions based on sizeof
  504. ensure that the function called has the right argument format, as
  505. for other <tgmath.h> macros for compilers before GCC 8, but may not
  506. have exactly the argument type (among the types with that format)
  507. specified in the standard logic.
  508. In the case of macros for _Float32x return type, when _Float64x
  509. exists, _Float64 arguments should result in the *f64 function being
  510. called while _Float32x arguments should result in the *f64x
  511. function being called. These cases cannot be distinguished using
  512. sizeof (or at all if the types are typedefs rather than different
  513. types). However, for these functions it is OK (does not affect the
  514. final result) to call a function with any argument format at least
  515. as wide as all the floating-point arguments, unless that affects
  516. rounding of integer arguments. Integer arguments are considered to
  517. have type _Float64, so the *f64 functions are preferred for f32x*
  518. macros when no argument has a wider floating-point type. */
  519. # if __HAVE_FLOAT64X_LONG_DOUBLE && __HAVE_DISTINCT_FLOAT128
  520. # define __TGMATH_2_NARROW_F32(F, X, Y) \
  521. (__extension__ (sizeof ((__tgmath_real_type (X)) 0 \
  522. + (__tgmath_real_type (Y)) 0) > sizeof (_Float64) \
  523. ? __TGMATH_F128 ((X) + (Y), F, (X, Y)) \
  524. F ## f64x (X, Y) \
  525. : F ## f64 (X, Y)))
  526. # define __TGMATH_2_NARROW_F64(F, X, Y) \
  527. (__extension__ (sizeof ((__tgmath_real_type (X)) 0 \
  528. + (__tgmath_real_type (Y)) 0) > sizeof (_Float64) \
  529. ? __TGMATH_F128 ((X) + (Y), F, (X, Y)) \
  530. F ## f64x (X, Y) \
  531. : F ## f128 (X, Y)))
  532. # define __TGMATH_2_NARROW_F32X(F, X, Y) \
  533. (__extension__ (sizeof ((__tgmath_real_type (X)) 0 \
  534. + (__tgmath_real_type (Y)) 0) > sizeof (_Float64) \
  535. ? __TGMATH_F128 ((X) + (Y), F, (X, Y)) \
  536. F ## f64x (X, Y) \
  537. : F ## f64 (X, Y)))
  538. # elif __HAVE_FLOAT128
  539. # define __TGMATH_2_NARROW_F32(F, X, Y) \
  540. (__extension__ (sizeof ((__tgmath_real_type (X)) 0 \
  541. + (__tgmath_real_type (Y)) 0) > sizeof (_Float64) \
  542. ? F ## f128 (X, Y) \
  543. : F ## f64 (X, Y)))
  544. # define __TGMATH_2_NARROW_F64(F, X, Y) \
  545. (F ## f128 (X, Y))
  546. # define __TGMATH_2_NARROW_F32X(F, X, Y) \
  547. (__extension__ (sizeof ((__tgmath_real_type (X)) 0 \
  548. + (__tgmath_real_type (Y)) 0) > sizeof (_Float32x) \
  549. ? F ## f64x (X, Y) \
  550. : F ## f64 (X, Y)))
  551. # else
  552. # define __TGMATH_2_NARROW_F32(F, X, Y) \
  553. (F ## f64 (X, Y))
  554. # endif
  555. # endif /* !__HAVE_BUILTIN_TGMATH. */
  556. #else
  557. # error "Unsupported compiler; you cannot use <tgmath.h>"
  558. #endif
  559. /* Unary functions defined for real and complex values. */
  560. /* Trigonometric functions. */
  561. /* Arc cosine of X. */
  562. #define acos(Val) __TGMATH_UNARY_REAL_IMAG (Val, acos, cacos)
  563. /* Arc sine of X. */
  564. #define asin(Val) __TGMATH_UNARY_REAL_IMAG (Val, asin, casin)
  565. /* Arc tangent of X. */
  566. #define atan(Val) __TGMATH_UNARY_REAL_IMAG (Val, atan, catan)
  567. /* Arc tangent of Y/X. */
  568. #define atan2(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, atan2)
  569. /* Cosine of X. */
  570. #define cos(Val) __TGMATH_UNARY_REAL_IMAG (Val, cos, ccos)
  571. /* Sine of X. */
  572. #define sin(Val) __TGMATH_UNARY_REAL_IMAG (Val, sin, csin)
  573. /* Tangent of X. */
  574. #define tan(Val) __TGMATH_UNARY_REAL_IMAG (Val, tan, ctan)
  575. /* Hyperbolic functions. */
  576. /* Hyperbolic arc cosine of X. */
  577. #define acosh(Val) __TGMATH_UNARY_REAL_IMAG (Val, acosh, cacosh)
  578. /* Hyperbolic arc sine of X. */
  579. #define asinh(Val) __TGMATH_UNARY_REAL_IMAG (Val, asinh, casinh)
  580. /* Hyperbolic arc tangent of X. */
  581. #define atanh(Val) __TGMATH_UNARY_REAL_IMAG (Val, atanh, catanh)
  582. /* Hyperbolic cosine of X. */
  583. #define cosh(Val) __TGMATH_UNARY_REAL_IMAG (Val, cosh, ccosh)
  584. /* Hyperbolic sine of X. */
  585. #define sinh(Val) __TGMATH_UNARY_REAL_IMAG (Val, sinh, csinh)
  586. /* Hyperbolic tangent of X. */
  587. #define tanh(Val) __TGMATH_UNARY_REAL_IMAG (Val, tanh, ctanh)
  588. /* Exponential and logarithmic functions. */
  589. /* Exponential function of X. */
  590. #define exp(Val) __TGMATH_UNARY_REAL_IMAG (Val, exp, cexp)
  591. /* Break VALUE into a normalized fraction and an integral power of 2. */
  592. #define frexp(Val1, Val2) __TGMATH_BINARY_FIRST_REAL_ONLY (Val1, Val2, frexp)
  593. /* X times (two to the EXP power). */
  594. #define ldexp(Val1, Val2) __TGMATH_BINARY_FIRST_REAL_ONLY (Val1, Val2, ldexp)
  595. /* Natural logarithm of X. */
  596. #define log(Val) __TGMATH_UNARY_REAL_IMAG (Val, log, clog)
  597. /* Base-ten logarithm of X. */
  598. #ifdef __USE_GNU
  599. # define log10(Val) __TGMATH_UNARY_REAL_IMAG (Val, log10, clog10)
  600. #else
  601. # define log10(Val) __TGMATH_UNARY_REAL_ONLY (Val, log10)
  602. #endif
  603. /* Return exp(X) - 1. */
  604. #define expm1(Val) __TGMATH_UNARY_REAL_ONLY (Val, expm1)
  605. /* Return log(1 + X). */
  606. #define log1p(Val) __TGMATH_UNARY_REAL_ONLY (Val, log1p)
  607. /* Return the base 2 signed integral exponent of X. */
  608. #define logb(Val) __TGMATH_UNARY_REAL_ONLY (Val, logb)
  609. /* Compute base-2 exponential of X. */
  610. #define exp2(Val) __TGMATH_UNARY_REAL_ONLY (Val, exp2)
  611. /* Compute base-2 logarithm of X. */
  612. #define log2(Val) __TGMATH_UNARY_REAL_ONLY (Val, log2)
  613. /* Power functions. */
  614. /* Return X to the Y power. */
  615. #define pow(Val1, Val2) __TGMATH_BINARY_REAL_IMAG (Val1, Val2, pow, cpow)
  616. /* Return the square root of X. */
  617. #define sqrt(Val) __TGMATH_UNARY_REAL_IMAG (Val, sqrt, csqrt)
  618. /* Return `sqrt(X*X + Y*Y)'. */
  619. #define hypot(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, hypot)
  620. /* Return the cube root of X. */
  621. #define cbrt(Val) __TGMATH_UNARY_REAL_ONLY (Val, cbrt)
  622. /* Nearest integer, absolute value, and remainder functions. */
  623. /* Smallest integral value not less than X. */
  624. #define ceil(Val) __TGMATH_UNARY_REAL_ONLY (Val, ceil)
  625. /* Absolute value of X. */
  626. #define fabs(Val) __TGMATH_UNARY_REAL_IMAG_RET_REAL (Val, fabs, cabs)
  627. /* Largest integer not greater than X. */
  628. #define floor(Val) __TGMATH_UNARY_REAL_ONLY (Val, floor)
  629. /* Floating-point modulo remainder of X/Y. */
  630. #define fmod(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, fmod)
  631. /* Round X to integral valuein floating-point format using current
  632. rounding direction, but do not raise inexact exception. */
  633. #define nearbyint(Val) __TGMATH_UNARY_REAL_ONLY (Val, nearbyint)
  634. /* Round X to nearest integral value, rounding halfway cases away from
  635. zero. */
  636. #define round(Val) __TGMATH_UNARY_REAL_ONLY (Val, round)
  637. /* Round X to the integral value in floating-point format nearest but
  638. not larger in magnitude. */
  639. #define trunc(Val) __TGMATH_UNARY_REAL_ONLY (Val, trunc)
  640. /* Compute remainder of X and Y and put in *QUO a value with sign of x/y
  641. and magnitude congruent `mod 2^n' to the magnitude of the integral
  642. quotient x/y, with n >= 3. */
  643. #define remquo(Val1, Val2, Val3) \
  644. __TGMATH_TERNARY_FIRST_SECOND_REAL_ONLY (Val1, Val2, Val3, remquo)
  645. /* Round X to nearest integral value according to current rounding
  646. direction. */
  647. #define lrint(Val) __TGMATH_UNARY_REAL_RET_ONLY (Val, lrint)
  648. #define llrint(Val) __TGMATH_UNARY_REAL_RET_ONLY (Val, llrint)
  649. /* Round X to nearest integral value, rounding halfway cases away from
  650. zero. */
  651. #define lround(Val) __TGMATH_UNARY_REAL_RET_ONLY (Val, lround)
  652. #define llround(Val) __TGMATH_UNARY_REAL_RET_ONLY (Val, llround)
  653. /* Return X with its signed changed to Y's. */
  654. #define copysign(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, copysign)
  655. /* Error and gamma functions. */
  656. #define erf(Val) __TGMATH_UNARY_REAL_ONLY (Val, erf)
  657. #define erfc(Val) __TGMATH_UNARY_REAL_ONLY (Val, erfc)
  658. #define tgamma(Val) __TGMATH_UNARY_REAL_ONLY (Val, tgamma)
  659. #define lgamma(Val) __TGMATH_UNARY_REAL_ONLY (Val, lgamma)
  660. /* Return the integer nearest X in the direction of the
  661. prevailing rounding mode. */
  662. #define rint(Val) __TGMATH_UNARY_REAL_ONLY (Val, rint)
  663. #if __GLIBC_USE (IEC_60559_BFP_EXT_C2X)
  664. /* Return X - epsilon. */
  665. # define nextdown(Val) __TGMATH_UNARY_REAL_ONLY (Val, nextdown)
  666. /* Return X + epsilon. */
  667. # define nextup(Val) __TGMATH_UNARY_REAL_ONLY (Val, nextup)
  668. #endif
  669. /* Return X + epsilon if X < Y, X - epsilon if X > Y. */
  670. #define nextafter(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, nextafter)
  671. #define nexttoward(Val1, Val2) \
  672. __TGMATH_BINARY_FIRST_REAL_STD_ONLY (Val1, Val2, nexttoward)
  673. /* Return the remainder of integer divison X / Y with infinite precision. */
  674. #define remainder(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, remainder)
  675. /* Return X times (2 to the Nth power). */
  676. #ifdef __USE_MISC
  677. # define scalb(Val1, Val2) __TGMATH_BINARY_REAL_STD_ONLY (Val1, Val2, scalb)
  678. #endif
  679. /* Return X times (2 to the Nth power). */
  680. #define scalbn(Val1, Val2) __TGMATH_BINARY_FIRST_REAL_ONLY (Val1, Val2, scalbn)
  681. /* Return X times (2 to the Nth power). */
  682. #define scalbln(Val1, Val2) \
  683. __TGMATH_BINARY_FIRST_REAL_ONLY (Val1, Val2, scalbln)
  684. /* Return the binary exponent of X, which must be nonzero. */
  685. #define ilogb(Val) __TGMATH_UNARY_REAL_RET_ONLY (Val, ilogb)
  686. /* Return positive difference between X and Y. */
  687. #define fdim(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, fdim)
  688. /* Return maximum numeric value from X and Y. */
  689. #define fmax(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, fmax)
  690. /* Return minimum numeric value from X and Y. */
  691. #define fmin(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, fmin)
  692. /* Multiply-add function computed as a ternary operation. */
  693. #define fma(Val1, Val2, Val3) \
  694. __TGMATH_TERNARY_REAL_ONLY (Val1, Val2, Val3, fma)
  695. #if __GLIBC_USE (IEC_60559_BFP_EXT_C2X)
  696. /* Round X to nearest integer value, rounding halfway cases to even. */
  697. # define roundeven(Val) __TGMATH_UNARY_REAL_ONLY (Val, roundeven)
  698. # define fromfp(Val1, Val2, Val3) \
  699. __TGMATH_TERNARY_FIRST_REAL_RET_ONLY (Val1, Val2, Val3, fromfp)
  700. # define ufromfp(Val1, Val2, Val3) \
  701. __TGMATH_TERNARY_FIRST_REAL_RET_ONLY (Val1, Val2, Val3, ufromfp)
  702. # define fromfpx(Val1, Val2, Val3) \
  703. __TGMATH_TERNARY_FIRST_REAL_RET_ONLY (Val1, Val2, Val3, fromfpx)
  704. # define ufromfpx(Val1, Val2, Val3) \
  705. __TGMATH_TERNARY_FIRST_REAL_RET_ONLY (Val1, Val2, Val3, ufromfpx)
  706. /* Like ilogb, but returning long int. */
  707. # define llogb(Val) __TGMATH_UNARY_REAL_RET_ONLY (Val, llogb)
  708. /* Return value with maximum magnitude. */
  709. # define fmaxmag(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, fmaxmag)
  710. /* Return value with minimum magnitude. */
  711. # define fminmag(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, fminmag)
  712. #endif
  713. /* Absolute value, conjugates, and projection. */
  714. /* Argument value of Z. */
  715. #define carg(Val) __TGMATH_UNARY_REAL_IMAG_RET_REAL_SAME (Val, carg)
  716. /* Complex conjugate of Z. */
  717. #define conj(Val) __TGMATH_UNARY_IMAG (Val, conj)
  718. /* Projection of Z onto the Riemann sphere. */
  719. #define cproj(Val) __TGMATH_UNARY_IMAG (Val, cproj)
  720. /* Decomposing complex values. */
  721. /* Imaginary part of Z. */
  722. #define cimag(Val) __TGMATH_UNARY_REAL_IMAG_RET_REAL_SAME (Val, cimag)
  723. /* Real part of Z. */
  724. #define creal(Val) __TGMATH_UNARY_REAL_IMAG_RET_REAL_SAME (Val, creal)
  725. /* Narrowing functions. */
  726. #if __GLIBC_USE (IEC_60559_BFP_EXT_C2X)
  727. /* Add. */
  728. # define fadd(Val1, Val2) __TGMATH_2_NARROW_F (fadd, Val1, Val2)
  729. # define dadd(Val1, Val2) __TGMATH_2_NARROW_D (dadd, Val1, Val2)
  730. /* Divide. */
  731. # define fdiv(Val1, Val2) __TGMATH_2_NARROW_F (fdiv, Val1, Val2)
  732. # define ddiv(Val1, Val2) __TGMATH_2_NARROW_D (ddiv, Val1, Val2)
  733. /* Multiply. */
  734. # define fmul(Val1, Val2) __TGMATH_2_NARROW_F (fmul, Val1, Val2)
  735. # define dmul(Val1, Val2) __TGMATH_2_NARROW_D (dmul, Val1, Val2)
  736. /* Subtract. */
  737. # define fsub(Val1, Val2) __TGMATH_2_NARROW_F (fsub, Val1, Val2)
  738. # define dsub(Val1, Val2) __TGMATH_2_NARROW_D (dsub, Val1, Val2)
  739. #endif
  740. #if __GLIBC_USE (IEC_60559_TYPES_EXT)
  741. # if __HAVE_FLOAT16
  742. # define f16add(Val1, Val2) __TGMATH_2_NARROW_F16 (f16add, Val1, Val2)
  743. # define f16div(Val1, Val2) __TGMATH_2_NARROW_F16 (f16div, Val1, Val2)
  744. # define f16mul(Val1, Val2) __TGMATH_2_NARROW_F16 (f16mul, Val1, Val2)
  745. # define f16sub(Val1, Val2) __TGMATH_2_NARROW_F16 (f16sub, Val1, Val2)
  746. # endif
  747. # if __HAVE_FLOAT32
  748. # define f32add(Val1, Val2) __TGMATH_2_NARROW_F32 (f32add, Val1, Val2)
  749. # define f32div(Val1, Val2) __TGMATH_2_NARROW_F32 (f32div, Val1, Val2)
  750. # define f32mul(Val1, Val2) __TGMATH_2_NARROW_F32 (f32mul, Val1, Val2)
  751. # define f32sub(Val1, Val2) __TGMATH_2_NARROW_F32 (f32sub, Val1, Val2)
  752. # endif
  753. # if __HAVE_FLOAT64 && (__HAVE_FLOAT64X || __HAVE_FLOAT128)
  754. # define f64add(Val1, Val2) __TGMATH_2_NARROW_F64 (f64add, Val1, Val2)
  755. # define f64div(Val1, Val2) __TGMATH_2_NARROW_F64 (f64div, Val1, Val2)
  756. # define f64mul(Val1, Val2) __TGMATH_2_NARROW_F64 (f64mul, Val1, Val2)
  757. # define f64sub(Val1, Val2) __TGMATH_2_NARROW_F64 (f64sub, Val1, Val2)
  758. # endif
  759. # if __HAVE_FLOAT32X
  760. # define f32xadd(Val1, Val2) __TGMATH_2_NARROW_F32X (f32xadd, Val1, Val2)
  761. # define f32xdiv(Val1, Val2) __TGMATH_2_NARROW_F32X (f32xdiv, Val1, Val2)
  762. # define f32xmul(Val1, Val2) __TGMATH_2_NARROW_F32X (f32xmul, Val1, Val2)
  763. # define f32xsub(Val1, Val2) __TGMATH_2_NARROW_F32X (f32xsub, Val1, Val2)
  764. # endif
  765. # if __HAVE_FLOAT64X && (__HAVE_FLOAT128X || __HAVE_FLOAT128)
  766. # define f64xadd(Val1, Val2) __TGMATH_2_NARROW_F64X (f64xadd, Val1, Val2)
  767. # define f64xdiv(Val1, Val2) __TGMATH_2_NARROW_F64X (f64xdiv, Val1, Val2)
  768. # define f64xmul(Val1, Val2) __TGMATH_2_NARROW_F64X (f64xmul, Val1, Val2)
  769. # define f64xsub(Val1, Val2) __TGMATH_2_NARROW_F64X (f64xsub, Val1, Val2)
  770. # endif
  771. #endif
  772. #endif /* tgmath.h */