math.h 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612
  1. /* Declarations for math functions.
  2. Copyright (C) 1991-2026 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library 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 GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <https://www.gnu.org/licenses/>. */
  15. /*
  16. * ISO C99 Standard: 7.12 Mathematics <math.h>
  17. */
  18. #ifndef _MATH_H
  19. #define _MATH_H 1
  20. #define __GLIBC_INTERNAL_STARTING_HEADER_IMPLEMENTATION
  21. #include <bits/libc-header-start.h>
  22. #if defined log && defined __GNUC__
  23. # warning A macro called log was already defined when <math.h> was included.
  24. # warning This will cause compilation problems.
  25. #endif
  26. __BEGIN_DECLS
  27. /* Get machine-dependent vector math functions declarations. */
  28. #include <bits/math-vector.h>
  29. /* Gather machine dependent type support. */
  30. #include <bits/floatn.h>
  31. #if __GLIBC_USE (ISOC23)
  32. # define __STDC_VERSION_MATH_H__ 202311L
  33. #endif
  34. /* Value returned on overflow. With IEEE 754 floating point, this is
  35. +Infinity, otherwise the largest representable positive value. */
  36. #if __GNUC_PREREQ (3, 3)
  37. # define HUGE_VAL (__builtin_huge_val ())
  38. #else
  39. /* This may provoke compiler warnings, and may not be rounded to
  40. +Infinity in all IEEE 754 rounding modes, but is the best that can
  41. be done in ISO C while remaining a constant expression. 10,000 is
  42. greater than the maximum (decimal) exponent for all supported
  43. floating-point formats and widths. */
  44. # define HUGE_VAL 1e10000
  45. #endif
  46. #ifdef __USE_ISOC99
  47. # if __GNUC_PREREQ (3, 3)
  48. # define HUGE_VALF (__builtin_huge_valf ())
  49. # define HUGE_VALL (__builtin_huge_vall ())
  50. # else
  51. # define HUGE_VALF 1e10000f
  52. # define HUGE_VALL 1e10000L
  53. # endif
  54. #endif
  55. #if __HAVE_FLOAT16 && __GLIBC_USE (IEC_60559_TYPES_EXT)
  56. # define HUGE_VAL_F16 (__builtin_huge_valf16 ())
  57. #endif
  58. #if __HAVE_FLOAT32 && __GLIBC_USE (IEC_60559_TYPES_EXT)
  59. # define HUGE_VAL_F32 (__builtin_huge_valf32 ())
  60. #endif
  61. #if __HAVE_FLOAT64 && __GLIBC_USE (IEC_60559_TYPES_EXT)
  62. # define HUGE_VAL_F64 (__builtin_huge_valf64 ())
  63. #endif
  64. #if __HAVE_FLOAT128 && __GLIBC_USE (IEC_60559_TYPES_EXT)
  65. # define HUGE_VAL_F128 (__builtin_huge_valf128 ())
  66. #endif
  67. #if __HAVE_FLOAT32X && __GLIBC_USE (IEC_60559_TYPES_EXT)
  68. # define HUGE_VAL_F32X (__builtin_huge_valf32x ())
  69. #endif
  70. #if __HAVE_FLOAT64X && __GLIBC_USE (IEC_60559_TYPES_EXT)
  71. # define HUGE_VAL_F64X (__builtin_huge_valf64x ())
  72. #endif
  73. #if __HAVE_FLOAT128X && __GLIBC_USE (IEC_60559_TYPES_EXT)
  74. # define HUGE_VAL_F128X (__builtin_huge_valf128x ())
  75. #endif
  76. #ifdef __USE_ISOC99
  77. /* IEEE positive infinity. */
  78. # ifndef INFINITY
  79. # if __GNUC_PREREQ (3, 3)
  80. # define INFINITY (__builtin_inff ())
  81. # else
  82. # define INFINITY HUGE_VALF
  83. # endif
  84. # endif
  85. /* IEEE Not A Number. */
  86. # ifndef NAN
  87. # if __GNUC_PREREQ (3, 3)
  88. # define NAN (__builtin_nanf (""))
  89. # else
  90. /* This will raise an "invalid" exception outside static initializers,
  91. but is the best that can be done in ISO C while remaining a
  92. constant expression. */
  93. # define NAN (0.0f / 0.0f)
  94. # endif
  95. # endif
  96. #endif /* __USE_ISOC99 */
  97. #if __GLIBC_USE (IEC_60559_BFP_EXT)
  98. /* Signaling NaN macros, if supported. */
  99. # if __GNUC_PREREQ (3, 3)
  100. # define SNANF (__builtin_nansf (""))
  101. # define SNAN (__builtin_nans (""))
  102. # define SNANL (__builtin_nansl (""))
  103. # endif
  104. #endif
  105. #if (__HAVE_FLOAT16 \
  106. && __GLIBC_USE (IEC_60559_TYPES_EXT) \
  107. && (defined __USE_GNU || !__GLIBC_USE (ISOC23)))
  108. # define SNANF16 (__builtin_nansf16 (""))
  109. #endif
  110. #if (__HAVE_FLOAT32 \
  111. && __GLIBC_USE (IEC_60559_TYPES_EXT) \
  112. && (defined __USE_GNU || !__GLIBC_USE (ISOC23)))
  113. # define SNANF32 (__builtin_nansf32 (""))
  114. #endif
  115. #if (__HAVE_FLOAT64 \
  116. && __GLIBC_USE (IEC_60559_TYPES_EXT) \
  117. && (defined __USE_GNU || !__GLIBC_USE (ISOC23)))
  118. # define SNANF64 (__builtin_nansf64 (""))
  119. #endif
  120. #if (__HAVE_FLOAT128 \
  121. && __GLIBC_USE (IEC_60559_TYPES_EXT) \
  122. && (defined __USE_GNU || !__GLIBC_USE (ISOC23)))
  123. # define SNANF128 (__builtin_nansf128 (""))
  124. #endif
  125. #if (__HAVE_FLOAT32X \
  126. && __GLIBC_USE (IEC_60559_TYPES_EXT) \
  127. && (defined __USE_GNU || !__GLIBC_USE (ISOC23)))
  128. # define SNANF32X (__builtin_nansf32x (""))
  129. #endif
  130. #if (__HAVE_FLOAT64X \
  131. && __GLIBC_USE (IEC_60559_TYPES_EXT) \
  132. && (defined __USE_GNU || !__GLIBC_USE (ISOC23)))
  133. # define SNANF64X (__builtin_nansf64x (""))
  134. #endif
  135. #if (__HAVE_FLOAT128X \
  136. && __GLIBC_USE (IEC_60559_TYPES_EXT) \
  137. && (defined __USE_GNU || !__GLIBC_USE (ISOC23)))
  138. # define SNANF128X (__builtin_nansf128x (""))
  139. #endif
  140. /* Get __GLIBC_FLT_EVAL_METHOD. */
  141. #include <bits/flt-eval-method.h>
  142. #ifdef __USE_ISOC99
  143. /* Define the following typedefs.
  144. float_t floating-point type at least as wide as `float' used
  145. to evaluate `float' expressions
  146. double_t floating-point type at least as wide as `double' used
  147. to evaluate `double' expressions
  148. TS 18661-3 and C23 additionally define long_double_t and _FloatN_t.
  149. */
  150. # if __GLIBC_FLT_EVAL_METHOD == 0
  151. typedef float float_t;
  152. typedef double double_t;
  153. # if __GLIBC_USE (IEC_60559_TYPES_EXT)
  154. typedef long double long_double_t;
  155. # if __HAVE_FLOAT16
  156. typedef float _Float16_t;
  157. # endif
  158. # if __HAVE_FLOAT32
  159. typedef _Float32 _Float32_t;
  160. # endif
  161. # if __HAVE_FLOAT64
  162. typedef _Float64 _Float64_t;
  163. # endif
  164. # if __HAVE_FLOAT128
  165. typedef _Float128 _Float128_t;
  166. # endif
  167. # endif
  168. # elif __GLIBC_FLT_EVAL_METHOD == 1
  169. typedef double float_t;
  170. typedef double double_t;
  171. # if __GLIBC_USE (IEC_60559_TYPES_EXT)
  172. typedef long double long_double_t;
  173. # if __HAVE_FLOAT16
  174. typedef double _Float16_t;
  175. # endif
  176. # if __HAVE_FLOAT32
  177. typedef double _Float32_t;
  178. # endif
  179. # if __HAVE_FLOAT64
  180. typedef _Float64 _Float64_t;
  181. # endif
  182. # if __HAVE_FLOAT128
  183. typedef _Float128 _Float128_t;
  184. # endif
  185. # endif
  186. # elif __GLIBC_FLT_EVAL_METHOD == 2
  187. typedef long double float_t;
  188. typedef long double double_t;
  189. # if __GLIBC_USE (IEC_60559_TYPES_EXT)
  190. typedef long double long_double_t;
  191. # if __HAVE_FLOAT16
  192. typedef long double _Float16_t;
  193. # endif
  194. # if __HAVE_FLOAT32
  195. typedef long double _Float32_t;
  196. # endif
  197. # if __HAVE_FLOAT64
  198. # ifdef __NO_LONG_DOUBLE_MATH
  199. typedef _Float64 _Float64_t;
  200. # else
  201. typedef long double _Float64_t;
  202. # endif
  203. # endif
  204. # if __HAVE_FLOAT128
  205. typedef _Float128 _Float128_t;
  206. # endif
  207. # endif
  208. # elif __GLIBC_FLT_EVAL_METHOD == 16
  209. typedef float float_t;
  210. typedef double double_t;
  211. # if __GLIBC_USE (IEC_60559_TYPES_EXT)
  212. typedef long double long_double_t;
  213. # if __HAVE_FLOAT16
  214. typedef _Float16 _Float16_t;
  215. # endif
  216. # if __HAVE_FLOAT32
  217. typedef _Float32 _Float32_t;
  218. # endif
  219. # if __HAVE_FLOAT64
  220. typedef _Float64 _Float64_t;
  221. # endif
  222. # if __HAVE_FLOAT128
  223. typedef _Float128 _Float128_t;
  224. # endif
  225. # endif
  226. # elif __GLIBC_FLT_EVAL_METHOD == 32
  227. typedef float float_t;
  228. typedef double double_t;
  229. # if __GLIBC_USE (IEC_60559_TYPES_EXT)
  230. typedef long double long_double_t;
  231. # if __HAVE_FLOAT16
  232. typedef _Float32 _Float16_t;
  233. # endif
  234. # if __HAVE_FLOAT32
  235. typedef _Float32 _Float32_t;
  236. # endif
  237. # if __HAVE_FLOAT64
  238. typedef _Float64 _Float64_t;
  239. # endif
  240. # if __HAVE_FLOAT128
  241. typedef _Float128 _Float128_t;
  242. # endif
  243. # endif
  244. # elif __GLIBC_FLT_EVAL_METHOD == 33
  245. typedef _Float32x float_t;
  246. typedef double double_t;
  247. # if __GLIBC_USE (IEC_60559_TYPES_EXT)
  248. typedef long double long_double_t;
  249. # if __HAVE_FLOAT16
  250. typedef _Float32x _Float16_t;
  251. # endif
  252. # if __HAVE_FLOAT32
  253. typedef _Float32x _Float32_t;
  254. # endif
  255. # if __HAVE_FLOAT64
  256. typedef _Float64 _Float64_t;
  257. # endif
  258. # if __HAVE_FLOAT128
  259. typedef _Float128 _Float128_t;
  260. # endif
  261. # endif
  262. # elif __GLIBC_FLT_EVAL_METHOD == 64
  263. typedef _Float64 float_t;
  264. typedef double double_t;
  265. # if __GLIBC_USE (IEC_60559_TYPES_EXT)
  266. typedef long double long_double_t;
  267. # if __HAVE_FLOAT16
  268. typedef _Float64 _Float16_t;
  269. # endif
  270. # if __HAVE_FLOAT32
  271. typedef _Float64 _Float32_t;
  272. # endif
  273. # if __HAVE_FLOAT64
  274. typedef _Float64 _Float64_t;
  275. # endif
  276. # if __HAVE_FLOAT128
  277. typedef _Float128 _Float128_t;
  278. # endif
  279. # endif
  280. # elif __GLIBC_FLT_EVAL_METHOD == 65
  281. typedef _Float64x float_t;
  282. typedef _Float64x double_t;
  283. # if __GLIBC_USE (IEC_60559_TYPES_EXT)
  284. typedef long double long_double_t;
  285. # if __HAVE_FLOAT16
  286. typedef _Float64x _Float16_t;
  287. # endif
  288. # if __HAVE_FLOAT32
  289. typedef _Float64x _Float32_t;
  290. # endif
  291. # if __HAVE_FLOAT64
  292. typedef _Float64x _Float64_t;
  293. # endif
  294. # if __HAVE_FLOAT128
  295. typedef _Float128 _Float128_t;
  296. # endif
  297. # endif
  298. # elif __GLIBC_FLT_EVAL_METHOD == 128
  299. typedef _Float128 float_t;
  300. typedef _Float128 double_t;
  301. # if __GLIBC_USE (IEC_60559_TYPES_EXT)
  302. # if __HAVE_FLOAT128_UNLIKE_LDBL && __LDBL_MANT_DIG__ != 106
  303. typedef _Float128 long_double_t;
  304. # else
  305. typedef long double long_double_t;
  306. # endif
  307. # if __HAVE_FLOAT16
  308. typedef _Float128 _Float16_t;
  309. # endif
  310. # if __HAVE_FLOAT32
  311. typedef _Float128 _Float32_t;
  312. # endif
  313. # if __HAVE_FLOAT64
  314. typedef _Float128 _Float64_t;
  315. # endif
  316. # if __HAVE_FLOAT128
  317. typedef _Float128 _Float128_t;
  318. # endif
  319. # endif
  320. # elif __GLIBC_FLT_EVAL_METHOD == 129
  321. typedef _Float128x float_t;
  322. typedef _Float128x double_t;
  323. # if __GLIBC_USE (IEC_60559_TYPES_EXT)
  324. # if __LDBL_MANT_DIG__ != 106
  325. typedef _Float128x long_double_t;
  326. # else
  327. typedef long double long_double_t;
  328. # endif
  329. # if __HAVE_FLOAT16
  330. typedef _Float128x _Float16_t;
  331. # endif
  332. # if __HAVE_FLOAT32
  333. typedef _Float128x _Float32_t;
  334. # endif
  335. # if __HAVE_FLOAT64
  336. typedef _Float128x _Float64_t;
  337. # endif
  338. # if __HAVE_FLOAT128
  339. typedef _Float128x _Float128_t;
  340. # endif
  341. # endif
  342. # else
  343. # error "Unknown __GLIBC_FLT_EVAL_METHOD"
  344. # endif
  345. #endif
  346. /* Define macros for the return values of ilogb and llogb, based on
  347. __FP_LOGB0_IS_MIN and __FP_LOGBNAN_IS_MIN.
  348. FP_ILOGB0 Expands to a value returned by `ilogb (0.0)'.
  349. FP_ILOGBNAN Expands to a value returned by `ilogb (NAN)'.
  350. FP_LLOGB0 Expands to a value returned by `llogb (0.0)'.
  351. FP_LLOGBNAN Expands to a value returned by `llogb (NAN)'.
  352. */
  353. #include <bits/fp-logb.h>
  354. #ifdef __USE_ISOC99
  355. # if __FP_LOGB0_IS_MIN
  356. # define FP_ILOGB0 (-2147483647 - 1)
  357. # else
  358. # define FP_ILOGB0 (-2147483647)
  359. # endif
  360. # if __FP_LOGBNAN_IS_MIN
  361. # define FP_ILOGBNAN (-2147483647 - 1)
  362. # else
  363. # define FP_ILOGBNAN 2147483647
  364. # endif
  365. #endif
  366. #if __GLIBC_USE (IEC_60559_BFP_EXT_C23)
  367. # if __WORDSIZE == 32
  368. # define __FP_LONG_MAX 0x7fffffffL
  369. # else
  370. # define __FP_LONG_MAX 0x7fffffffffffffffL
  371. # endif
  372. # if __FP_LOGB0_IS_MIN
  373. # define FP_LLOGB0 (-__FP_LONG_MAX - 1)
  374. # else
  375. # define FP_LLOGB0 (-__FP_LONG_MAX)
  376. # endif
  377. # if __FP_LOGBNAN_IS_MIN
  378. # define FP_LLOGBNAN (-__FP_LONG_MAX - 1)
  379. # else
  380. # define FP_LLOGBNAN __FP_LONG_MAX
  381. # endif
  382. #endif
  383. /* Get the architecture specific values describing the floating-point
  384. evaluation. The following symbols will get defined:
  385. FP_FAST_FMA
  386. FP_FAST_FMAF
  387. FP_FAST_FMAL
  388. If defined it indicates that the `fma' function
  389. generally executes about as fast as a multiply and an add.
  390. This macro is defined only iff the `fma' function is
  391. implemented directly with a hardware multiply-add instructions.
  392. */
  393. #include <bits/fp-fast.h>
  394. #if __GLIBC_USE (IEC_60559_BFP_EXT_C23)
  395. /* Rounding direction macros for fromfp functions. */
  396. enum
  397. {
  398. FP_INT_UPWARD =
  399. # define FP_INT_UPWARD 0
  400. FP_INT_UPWARD,
  401. FP_INT_DOWNWARD =
  402. # define FP_INT_DOWNWARD 1
  403. FP_INT_DOWNWARD,
  404. FP_INT_TOWARDZERO =
  405. # define FP_INT_TOWARDZERO 2
  406. FP_INT_TOWARDZERO,
  407. FP_INT_TONEARESTFROMZERO =
  408. # define FP_INT_TONEARESTFROMZERO 3
  409. FP_INT_TONEARESTFROMZERO,
  410. FP_INT_TONEAREST =
  411. # define FP_INT_TONEAREST 4
  412. FP_INT_TONEAREST,
  413. };
  414. #endif
  415. #include <bits/mathcalls-macros.h>
  416. #define _Mdouble_ double
  417. #define __MATH_PRECNAME(name,r) __CONCAT(name,r)
  418. #define __MATH_DECLARING_DOUBLE 1
  419. #define __MATH_DECLARING_FLOATN 0
  420. #include <bits/mathcalls-helper-functions.h>
  421. #include <bits/mathcalls.h>
  422. #undef _Mdouble_
  423. #undef __MATH_PRECNAME
  424. #undef __MATH_DECLARING_DOUBLE
  425. #undef __MATH_DECLARING_FLOATN
  426. #ifdef __USE_ISOC99
  427. /* Include the file of declarations again, this time using `float'
  428. instead of `double' and appending f to each function name. */
  429. # define _Mdouble_ float
  430. # define __MATH_PRECNAME(name,r) name##f##r
  431. # define __MATH_DECLARING_DOUBLE 0
  432. # define __MATH_DECLARING_FLOATN 0
  433. # include <bits/mathcalls-helper-functions.h>
  434. # include <bits/mathcalls.h>
  435. # undef _Mdouble_
  436. # undef __MATH_PRECNAME
  437. # undef __MATH_DECLARING_DOUBLE
  438. # undef __MATH_DECLARING_FLOATN
  439. # if !(defined __NO_LONG_DOUBLE_MATH && defined _LIBC) \
  440. || defined __LDBL_COMPAT \
  441. || defined _LIBC_TEST
  442. # ifdef __LDBL_COMPAT
  443. # ifdef __USE_ISOC99
  444. extern float __nldbl_nexttowardf (float __x, long double __y)
  445. __THROW __attribute__ ((__const__));
  446. # ifdef __REDIRECT_NTH
  447. extern float __REDIRECT_NTH (nexttowardf, (float __x, long double __y),
  448. __nldbl_nexttowardf)
  449. __attribute__ ((__const__));
  450. extern double __REDIRECT_NTH (nexttoward, (double __x, long double __y),
  451. nextafter) __attribute__ ((__const__));
  452. extern long double __REDIRECT_NTH (nexttowardl,
  453. (long double __x, long double __y),
  454. nextafter) __attribute__ ((__const__));
  455. # endif
  456. # endif
  457. # undef __MATHDECL_1
  458. # define __MATHDECL_1(type, function,suffix, args) \
  459. __MATHREDIR(type, function, suffix, args, __CONCAT(function,suffix))
  460. # elif __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1
  461. # ifdef __REDIRECT_NTH
  462. # ifdef __USE_ISOC99
  463. extern float __REDIRECT_NTH (nexttowardf, (float __x, long double __y),
  464. __nexttowardf_to_ieee128)
  465. __attribute__ ((__const__));
  466. extern double __REDIRECT_NTH (nexttoward, (double __x, long double __y),
  467. __nexttoward_to_ieee128)
  468. __attribute__ ((__const__));
  469. #define __dremieee128 __remainderieee128
  470. #define __gammaieee128 __lgammaieee128
  471. # endif
  472. # endif
  473. # undef __MATHDECL_1
  474. # undef __MATHDECL_ALIAS
  475. # define __REDIRTO(function, suffix) \
  476. __ ## function ## ieee128 ## suffix
  477. # define __REDIRTO_ALT(function, suffix) \
  478. __ ## function ## f128 ## suffix
  479. # define __MATHDECL_1(type, function, suffix, args) \
  480. __MATHREDIR (type, function, suffix, args, __REDIRTO (function, suffix))
  481. # define __MATHDECL_ALIAS(type, function, suffix, args, alias) \
  482. __MATHREDIR (type, function, suffix, args, __REDIRTO_ALT (alias, suffix))
  483. # endif
  484. /* Include the file of declarations again, this time using `long double'
  485. instead of `double' and appending l to each function name. */
  486. # define _Mdouble_ long double
  487. # define __MATH_PRECNAME(name,r) name##l##r
  488. # define __MATH_DECLARING_DOUBLE 0
  489. # define __MATH_DECLARING_FLOATN 0
  490. # define __MATH_DECLARE_LDOUBLE 1
  491. # include <bits/mathcalls-helper-functions.h>
  492. # include <bits/mathcalls.h>
  493. # undef _Mdouble_
  494. # undef __MATH_PRECNAME
  495. # undef __MATH_DECLARING_DOUBLE
  496. # undef __MATH_DECLARING_FLOATN
  497. # if defined __LDBL_COMPAT \
  498. || __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1
  499. # undef __REDIRTO
  500. # undef __REDIRTO_ALT
  501. # undef __MATHDECL_1
  502. # undef __MATHDECL_ALIAS
  503. # define __MATHDECL_1(type, function, suffix, args) \
  504. __MATHDECL_1_IMPL(type, function, suffix, args)
  505. # define __MATHDECL_ALIAS(type, function, suffix, args, alias) \
  506. __MATHDECL_1(type, function, suffix, args)
  507. # endif
  508. # endif /* !(__NO_LONG_DOUBLE_MATH && _LIBC) || __LDBL_COMPAT */
  509. #endif /* Use ISO C99. */
  510. /* Include the file of declarations for _FloatN and _FloatNx
  511. types. */
  512. #if __HAVE_DISTINCT_FLOAT16 || (__HAVE_FLOAT16 && !defined _LIBC)
  513. # define _Mdouble_ _Float16
  514. # define __MATH_PRECNAME(name,r) name##f16##r
  515. # define __MATH_DECLARING_DOUBLE 0
  516. # define __MATH_DECLARING_FLOATN 1
  517. # if __HAVE_DISTINCT_FLOAT16
  518. # include <bits/mathcalls-helper-functions.h>
  519. # endif
  520. # if __GLIBC_USE (IEC_60559_TYPES_EXT)
  521. # include <bits/mathcalls.h>
  522. # endif
  523. # undef _Mdouble_
  524. # undef __MATH_PRECNAME
  525. # undef __MATH_DECLARING_DOUBLE
  526. # undef __MATH_DECLARING_FLOATN
  527. #endif /* __HAVE_DISTINCT_FLOAT16 || (__HAVE_FLOAT16 && !_LIBC). */
  528. #if __HAVE_DISTINCT_FLOAT32 || (__HAVE_FLOAT32 && !defined _LIBC)
  529. # define _Mdouble_ _Float32
  530. # define __MATH_PRECNAME(name,r) name##f32##r
  531. # define __MATH_DECLARING_DOUBLE 0
  532. # define __MATH_DECLARING_FLOATN 1
  533. # if __HAVE_DISTINCT_FLOAT32
  534. # include <bits/mathcalls-helper-functions.h>
  535. # endif
  536. # if __GLIBC_USE (IEC_60559_TYPES_EXT)
  537. # include <bits/mathcalls.h>
  538. # endif
  539. # undef _Mdouble_
  540. # undef __MATH_PRECNAME
  541. # undef __MATH_DECLARING_DOUBLE
  542. # undef __MATH_DECLARING_FLOATN
  543. #endif /* __HAVE_DISTINCT_FLOAT32 || (__HAVE_FLOAT32 && !_LIBC). */
  544. #if __HAVE_DISTINCT_FLOAT64 || (__HAVE_FLOAT64 && !defined _LIBC)
  545. # define _Mdouble_ _Float64
  546. # define __MATH_PRECNAME(name,r) name##f64##r
  547. # define __MATH_DECLARING_DOUBLE 0
  548. # define __MATH_DECLARING_FLOATN 1
  549. # if __HAVE_DISTINCT_FLOAT64
  550. # include <bits/mathcalls-helper-functions.h>
  551. # endif
  552. # if __GLIBC_USE (IEC_60559_TYPES_EXT)
  553. # include <bits/mathcalls.h>
  554. # endif
  555. # undef _Mdouble_
  556. # undef __MATH_PRECNAME
  557. # undef __MATH_DECLARING_DOUBLE
  558. # undef __MATH_DECLARING_FLOATN
  559. #endif /* __HAVE_DISTINCT_FLOAT64 || (__HAVE_FLOAT64 && !_LIBC). */
  560. #if __HAVE_DISTINCT_FLOAT128 || (__HAVE_FLOAT128 && !defined _LIBC)
  561. # define _Mdouble_ _Float128
  562. # define __MATH_PRECNAME(name,r) name##f128##r
  563. # define __MATH_DECLARING_DOUBLE 0
  564. # define __MATH_DECLARING_FLOATN 1
  565. # if __HAVE_DISTINCT_FLOAT128
  566. # include <bits/mathcalls-helper-functions.h>
  567. # endif
  568. # if __GLIBC_USE (IEC_60559_TYPES_EXT)
  569. # include <bits/mathcalls.h>
  570. # endif
  571. # undef _Mdouble_
  572. # undef __MATH_PRECNAME
  573. # undef __MATH_DECLARING_DOUBLE
  574. # undef __MATH_DECLARING_FLOATN
  575. #endif /* __HAVE_DISTINCT_FLOAT128 || (__HAVE_FLOAT128 && !_LIBC). */
  576. #if __HAVE_DISTINCT_FLOAT32X || (__HAVE_FLOAT32X && !defined _LIBC)
  577. # define _Mdouble_ _Float32x
  578. # define __MATH_PRECNAME(name,r) name##f32x##r
  579. # define __MATH_DECLARING_DOUBLE 0
  580. # define __MATH_DECLARING_FLOATN 1
  581. # if __HAVE_DISTINCT_FLOAT32X
  582. # include <bits/mathcalls-helper-functions.h>
  583. # endif
  584. # if __GLIBC_USE (IEC_60559_TYPES_EXT)
  585. # include <bits/mathcalls.h>
  586. # endif
  587. # undef _Mdouble_
  588. # undef __MATH_PRECNAME
  589. # undef __MATH_DECLARING_DOUBLE
  590. # undef __MATH_DECLARING_FLOATN
  591. #endif /* __HAVE_DISTINCT_FLOAT32X || (__HAVE_FLOAT32X && !_LIBC). */
  592. #if __HAVE_DISTINCT_FLOAT64X || (__HAVE_FLOAT64X && !defined _LIBC)
  593. # define _Mdouble_ _Float64x
  594. # define __MATH_PRECNAME(name,r) name##f64x##r
  595. # define __MATH_DECLARING_DOUBLE 0
  596. # define __MATH_DECLARING_FLOATN 1
  597. # if __HAVE_DISTINCT_FLOAT64X
  598. # include <bits/mathcalls-helper-functions.h>
  599. # endif
  600. # if __GLIBC_USE (IEC_60559_TYPES_EXT)
  601. # include <bits/mathcalls.h>
  602. # endif
  603. # undef _Mdouble_
  604. # undef __MATH_PRECNAME
  605. # undef __MATH_DECLARING_DOUBLE
  606. # undef __MATH_DECLARING_FLOATN
  607. #endif /* __HAVE_DISTINCT_FLOAT64X || (__HAVE_FLOAT64X && !_LIBC). */
  608. #if __HAVE_DISTINCT_FLOAT128X || (__HAVE_FLOAT128X && !defined _LIBC)
  609. # define _Mdouble_ _Float128x
  610. # define __MATH_PRECNAME(name,r) name##f128x##r
  611. # define __MATH_DECLARING_DOUBLE 0
  612. # define __MATH_DECLARING_FLOATN 1
  613. # if __HAVE_DISTINCT_FLOAT128X
  614. # include <bits/mathcalls-helper-functions.h>
  615. # endif
  616. # if __GLIBC_USE (IEC_60559_TYPES_EXT)
  617. # include <bits/mathcalls.h>
  618. # endif
  619. # undef _Mdouble_
  620. # undef __MATH_PRECNAME
  621. # undef __MATH_DECLARING_DOUBLE
  622. # undef __MATH_DECLARING_FLOATN
  623. #endif /* __HAVE_DISTINCT_FLOAT128X || (__HAVE_FLOAT128X && !_LIBC). */
  624. #undef __MATHDECL_1_IMPL
  625. #undef __MATHDECL_1
  626. #undef __MATHDECL_ALIAS
  627. #undef __MATHDECL
  628. #undef __MATHCALL
  629. /* Declare functions returning a narrower type. */
  630. #define __MATHCALL_NARROW_ARGS_1 (_Marg_ __x)
  631. #define __MATHCALL_NARROW_ARGS_2 (_Marg_ __x, _Marg_ __y)
  632. #define __MATHCALL_NARROW_ARGS_3 (_Marg_ __x, _Marg_ __y, _Marg_ __z)
  633. #define __MATHCALL_NARROW_NORMAL(func, nargs) \
  634. extern _Mret_ func __MATHCALL_NARROW_ARGS_ ## nargs __THROW
  635. #define __MATHCALL_NARROW_REDIR(func, redir, nargs) \
  636. extern _Mret_ __REDIRECT_NTH (func, __MATHCALL_NARROW_ARGS_ ## nargs, \
  637. redir)
  638. #define __MATHCALL_NARROW(func, redir, nargs) \
  639. __MATHCALL_NARROW_NORMAL (func, nargs)
  640. #if __GLIBC_USE (IEC_60559_BFP_EXT_C23)
  641. # define _Mret_ float
  642. # define _Marg_ double
  643. # define __MATHCALL_NAME(name) f ## name
  644. # include <bits/mathcalls-narrow.h>
  645. # undef _Mret_
  646. # undef _Marg_
  647. # undef __MATHCALL_NAME
  648. # define _Mret_ float
  649. # define _Marg_ long double
  650. # define __MATHCALL_NAME(name) f ## name ## l
  651. # ifdef __LDBL_COMPAT
  652. # define __MATHCALL_REDIR_NAME(name) f ## name
  653. # define __MATHCALL_REDIR_NAME2(name) f ## name
  654. # undef __MATHCALL_NARROW
  655. # define __MATHCALL_NARROW(func, redir, nargs) \
  656. __MATHCALL_NARROW_REDIR (func, redir, nargs)
  657. # elif __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1
  658. # define __MATHCALL_REDIR_NAME(name) __ ## f32 ## name ## ieee128
  659. # define __MATHCALL_REDIR_NAME2(name) __ ## f32 ## name ## ieee128
  660. # undef __MATHCALL_NARROW
  661. # define __MATHCALL_NARROW(func, redir, nargs) \
  662. __MATHCALL_NARROW_REDIR (func, redir, nargs)
  663. # endif
  664. # include <bits/mathcalls-narrow.h>
  665. # undef _Mret_
  666. # undef _Marg_
  667. # undef __MATHCALL_NAME
  668. # if defined __LDBL_COMPAT \
  669. || __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1
  670. # undef __MATHCALL_REDIR_NAME
  671. # undef __MATHCALL_REDIR_NAME2
  672. # undef __MATHCALL_NARROW
  673. # define __MATHCALL_NARROW(func, redir, nargs) \
  674. __MATHCALL_NARROW_NORMAL (func, nargs)
  675. # endif
  676. # define _Mret_ double
  677. # define _Marg_ long double
  678. # define __MATHCALL_NAME(name) d ## name ## l
  679. # ifdef __LDBL_COMPAT
  680. # define __MATHCALL_REDIR_NAME(name) __nldbl_d ## name ## l
  681. # define __MATHCALL_REDIR_NAME2(name) name
  682. # undef __MATHCALL_NARROW
  683. # define __MATHCALL_NARROW(func, redir, nargs) \
  684. __MATHCALL_NARROW_REDIR (func, redir, nargs)
  685. # elif __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1
  686. # define __MATHCALL_REDIR_NAME(name) __ ## f64 ## name ## ieee128
  687. # define __MATHCALL_REDIR_NAME2(name) __ ## f64 ## name ## ieee128
  688. # undef __MATHCALL_NARROW
  689. # define __MATHCALL_NARROW(func, redir, nargs) \
  690. __MATHCALL_NARROW_REDIR (func, redir, nargs)
  691. # endif
  692. # include <bits/mathcalls-narrow.h>
  693. # undef _Mret_
  694. # undef _Marg_
  695. # undef __MATHCALL_NAME
  696. # if defined __LDBL_COMPAT \
  697. || __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1
  698. # undef __MATHCALL_REDIR_NAME
  699. # undef __MATHCALL_REDIR_NAME2
  700. # undef __MATHCALL_NARROW
  701. # define __MATHCALL_NARROW(func, redir, nargs) \
  702. __MATHCALL_NARROW_NORMAL (func, nargs)
  703. # endif
  704. #endif
  705. #if __GLIBC_USE (IEC_60559_TYPES_EXT)
  706. # if __HAVE_FLOAT16 && __HAVE_FLOAT32
  707. # define _Mret_ _Float16
  708. # define _Marg_ _Float32
  709. # define __MATHCALL_NAME(name) f16 ## name ## f32
  710. # include <bits/mathcalls-narrow.h>
  711. # undef _Mret_
  712. # undef _Marg_
  713. # undef __MATHCALL_NAME
  714. # endif
  715. # if __HAVE_FLOAT16 && __HAVE_FLOAT32X
  716. # define _Mret_ _Float16
  717. # define _Marg_ _Float32x
  718. # define __MATHCALL_NAME(name) f16 ## name ## f32x
  719. # include <bits/mathcalls-narrow.h>
  720. # undef _Mret_
  721. # undef _Marg_
  722. # undef __MATHCALL_NAME
  723. # endif
  724. # if __HAVE_FLOAT16 && __HAVE_FLOAT64
  725. # define _Mret_ _Float16
  726. # define _Marg_ _Float64
  727. # define __MATHCALL_NAME(name) f16 ## name ## f64
  728. # include <bits/mathcalls-narrow.h>
  729. # undef _Mret_
  730. # undef _Marg_
  731. # undef __MATHCALL_NAME
  732. # endif
  733. # if __HAVE_FLOAT16 && __HAVE_FLOAT64X
  734. # define _Mret_ _Float16
  735. # define _Marg_ _Float64x
  736. # define __MATHCALL_NAME(name) f16 ## name ## f64x
  737. # include <bits/mathcalls-narrow.h>
  738. # undef _Mret_
  739. # undef _Marg_
  740. # undef __MATHCALL_NAME
  741. # endif
  742. # if __HAVE_FLOAT16 && __HAVE_FLOAT128
  743. # define _Mret_ _Float16
  744. # define _Marg_ _Float128
  745. # define __MATHCALL_NAME(name) f16 ## name ## f128
  746. # include <bits/mathcalls-narrow.h>
  747. # undef _Mret_
  748. # undef _Marg_
  749. # undef __MATHCALL_NAME
  750. # endif
  751. # if __HAVE_FLOAT16 && __HAVE_FLOAT128X
  752. # define _Mret_ _Float16
  753. # define _Marg_ _Float128x
  754. # define __MATHCALL_NAME(name) f16 ## name ## f128x
  755. # include <bits/mathcalls-narrow.h>
  756. # undef _Mret_
  757. # undef _Marg_
  758. # undef __MATHCALL_NAME
  759. # endif
  760. # if __HAVE_FLOAT32 && __HAVE_FLOAT32X
  761. # define _Mret_ _Float32
  762. # define _Marg_ _Float32x
  763. # define __MATHCALL_NAME(name) f32 ## name ## f32x
  764. # include <bits/mathcalls-narrow.h>
  765. # undef _Mret_
  766. # undef _Marg_
  767. # undef __MATHCALL_NAME
  768. # endif
  769. # if __HAVE_FLOAT32 && __HAVE_FLOAT64
  770. # define _Mret_ _Float32
  771. # define _Marg_ _Float64
  772. # define __MATHCALL_NAME(name) f32 ## name ## f64
  773. # include <bits/mathcalls-narrow.h>
  774. # undef _Mret_
  775. # undef _Marg_
  776. # undef __MATHCALL_NAME
  777. # endif
  778. # if __HAVE_FLOAT32 && __HAVE_FLOAT64X
  779. # define _Mret_ _Float32
  780. # define _Marg_ _Float64x
  781. # define __MATHCALL_NAME(name) f32 ## name ## f64x
  782. # include <bits/mathcalls-narrow.h>
  783. # undef _Mret_
  784. # undef _Marg_
  785. # undef __MATHCALL_NAME
  786. # endif
  787. # if __HAVE_FLOAT32 && __HAVE_FLOAT128
  788. # define _Mret_ _Float32
  789. # define _Marg_ _Float128
  790. # define __MATHCALL_NAME(name) f32 ## name ## f128
  791. # include <bits/mathcalls-narrow.h>
  792. # undef _Mret_
  793. # undef _Marg_
  794. # undef __MATHCALL_NAME
  795. # endif
  796. # if __HAVE_FLOAT32 && __HAVE_FLOAT128X
  797. # define _Mret_ _Float32
  798. # define _Marg_ _Float128x
  799. # define __MATHCALL_NAME(name) f32 ## name ## f128x
  800. # include <bits/mathcalls-narrow.h>
  801. # undef _Mret_
  802. # undef _Marg_
  803. # undef __MATHCALL_NAME
  804. # endif
  805. # if __HAVE_FLOAT32X && __HAVE_FLOAT64
  806. # define _Mret_ _Float32x
  807. # define _Marg_ _Float64
  808. # define __MATHCALL_NAME(name) f32x ## name ## f64
  809. # include <bits/mathcalls-narrow.h>
  810. # undef _Mret_
  811. # undef _Marg_
  812. # undef __MATHCALL_NAME
  813. # endif
  814. # if __HAVE_FLOAT32X && __HAVE_FLOAT64X
  815. # define _Mret_ _Float32x
  816. # define _Marg_ _Float64x
  817. # define __MATHCALL_NAME(name) f32x ## name ## f64x
  818. # include <bits/mathcalls-narrow.h>
  819. # undef _Mret_
  820. # undef _Marg_
  821. # undef __MATHCALL_NAME
  822. # endif
  823. # if __HAVE_FLOAT32X && __HAVE_FLOAT128
  824. # define _Mret_ _Float32x
  825. # define _Marg_ _Float128
  826. # define __MATHCALL_NAME(name) f32x ## name ## f128
  827. # include <bits/mathcalls-narrow.h>
  828. # undef _Mret_
  829. # undef _Marg_
  830. # undef __MATHCALL_NAME
  831. # endif
  832. # if __HAVE_FLOAT32X && __HAVE_FLOAT128X
  833. # define _Mret_ _Float32x
  834. # define _Marg_ _Float128x
  835. # define __MATHCALL_NAME(name) f32x ## name ## f128x
  836. # include <bits/mathcalls-narrow.h>
  837. # undef _Mret_
  838. # undef _Marg_
  839. # undef __MATHCALL_NAME
  840. # endif
  841. # if __HAVE_FLOAT64 && __HAVE_FLOAT64X
  842. # define _Mret_ _Float64
  843. # define _Marg_ _Float64x
  844. # define __MATHCALL_NAME(name) f64 ## name ## f64x
  845. # include <bits/mathcalls-narrow.h>
  846. # undef _Mret_
  847. # undef _Marg_
  848. # undef __MATHCALL_NAME
  849. # endif
  850. # if __HAVE_FLOAT64 && __HAVE_FLOAT128
  851. # define _Mret_ _Float64
  852. # define _Marg_ _Float128
  853. # define __MATHCALL_NAME(name) f64 ## name ## f128
  854. # include <bits/mathcalls-narrow.h>
  855. # undef _Mret_
  856. # undef _Marg_
  857. # undef __MATHCALL_NAME
  858. # endif
  859. # if __HAVE_FLOAT64 && __HAVE_FLOAT128X
  860. # define _Mret_ _Float64
  861. # define _Marg_ _Float128x
  862. # define __MATHCALL_NAME(name) f64 ## name ## f128x
  863. # include <bits/mathcalls-narrow.h>
  864. # undef _Mret_
  865. # undef _Marg_
  866. # undef __MATHCALL_NAME
  867. # endif
  868. # if __HAVE_FLOAT64X && __HAVE_FLOAT128
  869. # define _Mret_ _Float64x
  870. # define _Marg_ _Float128
  871. # define __MATHCALL_NAME(name) f64x ## name ## f128
  872. # include <bits/mathcalls-narrow.h>
  873. # undef _Mret_
  874. # undef _Marg_
  875. # undef __MATHCALL_NAME
  876. # endif
  877. # if __HAVE_FLOAT64X && __HAVE_FLOAT128X
  878. # define _Mret_ _Float64x
  879. # define _Marg_ _Float128x
  880. # define __MATHCALL_NAME(name) f64x ## name ## f128x
  881. # include <bits/mathcalls-narrow.h>
  882. # undef _Mret_
  883. # undef _Marg_
  884. # undef __MATHCALL_NAME
  885. # endif
  886. # if __HAVE_FLOAT128 && __HAVE_FLOAT128X
  887. # define _Mret_ _Float128
  888. # define _Marg_ _Float128x
  889. # define __MATHCALL_NAME(name) f128 ## name ## f128x
  890. # include <bits/mathcalls-narrow.h>
  891. # undef _Mret_
  892. # undef _Marg_
  893. # undef __MATHCALL_NAME
  894. # endif
  895. #endif
  896. #undef __MATHCALL_NARROW_ARGS_1
  897. #undef __MATHCALL_NARROW_ARGS_2
  898. #undef __MATHCALL_NARROW_ARGS_3
  899. #undef __MATHCALL_NARROW_NORMAL
  900. #undef __MATHCALL_NARROW_REDIR
  901. #undef __MATHCALL_NARROW
  902. #if defined __USE_MISC || defined __USE_XOPEN
  903. /* This variable is used by `gamma' and `lgamma'. */
  904. extern int signgam;
  905. #endif
  906. #if (__HAVE_DISTINCT_FLOAT16 \
  907. || __HAVE_DISTINCT_FLOAT32 \
  908. || __HAVE_DISTINCT_FLOAT64 \
  909. || __HAVE_DISTINCT_FLOAT32X \
  910. || __HAVE_DISTINCT_FLOAT64X \
  911. || __HAVE_DISTINCT_FLOAT128X)
  912. # error "Unsupported _FloatN or _FloatNx types for <math.h>."
  913. #endif
  914. /* Depending on the type of TG_ARG, call an appropriately suffixed
  915. version of FUNC with arguments (including parentheses) ARGS.
  916. Suffixed functions may not exist for long double if it has the same
  917. format as double, or for other types with the same format as float,
  918. double or long double. The behavior is undefined if the argument
  919. does not have a real floating type. The definition may use a
  920. conditional expression, so all suffixed versions of FUNC must
  921. return the same type (FUNC may include a cast if necessary rather
  922. than being a single identifier). */
  923. #ifdef __NO_LONG_DOUBLE_MATH
  924. # if __HAVE_DISTINCT_FLOAT128
  925. # error "Distinct _Float128 without distinct long double not supported."
  926. # endif
  927. # define __MATH_TG(TG_ARG, FUNC, ARGS) \
  928. (sizeof (TG_ARG) == sizeof (float) ? FUNC ## f ARGS : FUNC ARGS)
  929. #elif __HAVE_DISTINCT_FLOAT128
  930. # if __HAVE_GENERIC_SELECTION
  931. # if __HAVE_FLOATN_NOT_TYPEDEF && __HAVE_FLOAT32
  932. # define __MATH_TG_F32(FUNC, ARGS) _Float32: FUNC ## f ARGS,
  933. # else
  934. # define __MATH_TG_F32(FUNC, ARGS)
  935. # endif
  936. # if __HAVE_FLOATN_NOT_TYPEDEF && __HAVE_FLOAT64X
  937. # if __HAVE_FLOAT64X_LONG_DOUBLE
  938. # define __MATH_TG_F64X(FUNC, ARGS) _Float64x: FUNC ## l ARGS,
  939. # else
  940. # define __MATH_TG_F64X(FUNC, ARGS) _Float64x: FUNC ## f128 ARGS,
  941. # endif
  942. # else
  943. # define __MATH_TG_F64X(FUNC, ARGS)
  944. # endif
  945. # define __MATH_TG(TG_ARG, FUNC, ARGS) \
  946. _Generic ((TG_ARG), \
  947. float: FUNC ## f ARGS, \
  948. __MATH_TG_F32 (FUNC, ARGS) \
  949. default: FUNC ARGS, \
  950. long double: FUNC ## l ARGS, \
  951. __MATH_TG_F64X (FUNC, ARGS) \
  952. _Float128: FUNC ## f128 ARGS)
  953. # else
  954. # if __HAVE_FLOATN_NOT_TYPEDEF
  955. # error "Non-typedef _FloatN but no _Generic."
  956. # endif
  957. # define __MATH_TG(TG_ARG, FUNC, ARGS) \
  958. __builtin_choose_expr \
  959. (__builtin_types_compatible_p (__typeof (TG_ARG), float), \
  960. FUNC ## f ARGS, \
  961. __builtin_choose_expr \
  962. (__builtin_types_compatible_p (__typeof (TG_ARG), double), \
  963. FUNC ARGS, \
  964. __builtin_choose_expr \
  965. (__builtin_types_compatible_p (__typeof (TG_ARG), long double), \
  966. FUNC ## l ARGS, \
  967. FUNC ## f128 ARGS)))
  968. # endif
  969. #else
  970. # define __MATH_TG(TG_ARG, FUNC, ARGS) \
  971. (sizeof (TG_ARG) == sizeof (float) \
  972. ? FUNC ## f ARGS \
  973. : sizeof (TG_ARG) == sizeof (double) \
  974. ? FUNC ARGS \
  975. : FUNC ## l ARGS)
  976. #endif
  977. /* ISO C99 defines some generic macros which work on any data type. */
  978. #ifdef __USE_ISOC99
  979. /* All floating-point numbers can be put in one of these categories. */
  980. enum
  981. {
  982. FP_NAN =
  983. # define FP_NAN 0
  984. FP_NAN,
  985. FP_INFINITE =
  986. # define FP_INFINITE 1
  987. FP_INFINITE,
  988. FP_ZERO =
  989. # define FP_ZERO 2
  990. FP_ZERO,
  991. FP_SUBNORMAL =
  992. # define FP_SUBNORMAL 3
  993. FP_SUBNORMAL,
  994. FP_NORMAL =
  995. # define FP_NORMAL 4
  996. FP_NORMAL
  997. };
  998. /* GCC bug 66462 means we cannot use the math builtins with -fsignaling-nan,
  999. so disable builtins if this is enabled. When fixed in a newer GCC,
  1000. the __SUPPORT_SNAN__ check may be skipped for those versions. */
  1001. /* Return number of classification appropriate for X. */
  1002. # if ((__GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__) \
  1003. || __glibc_clang_prereq (2,8)) \
  1004. && (!defined __OPTIMIZE_SIZE__ || defined __cplusplus)
  1005. /* The check for __cplusplus allows the use of the builtin, even
  1006. when optimization for size is on. This is provided for
  1007. libstdc++, only to let its configure test work when it is built
  1008. with -Os. No further use of this definition of fpclassify is
  1009. expected in C++ mode, since libstdc++ provides its own version
  1010. of fpclassify in cmath (which undefines fpclassify). */
  1011. # define fpclassify(x) __builtin_fpclassify (FP_NAN, FP_INFINITE, \
  1012. FP_NORMAL, FP_SUBNORMAL, FP_ZERO, x)
  1013. # else
  1014. # define fpclassify(x) __MATH_TG ((x), __fpclassify, (x))
  1015. # endif
  1016. /* Return nonzero value if sign of X is negative. */
  1017. # if __GNUC_PREREQ (6,0) || __glibc_clang_prereq (3,3)
  1018. # define signbit(x) __builtin_signbit (x)
  1019. # elif defined __cplusplus
  1020. /* In C++ mode, __MATH_TG cannot be used, because it relies on
  1021. __builtin_types_compatible_p, which is a C-only builtin.
  1022. The check for __cplusplus allows the use of the builtin instead of
  1023. __MATH_TG. This is provided for libstdc++, only to let its configure
  1024. test work. No further use of this definition of signbit is expected
  1025. in C++ mode, since libstdc++ provides its own version of signbit
  1026. in cmath (which undefines signbit). */
  1027. # define signbit(x) __builtin_signbitl (x)
  1028. # elif __GNUC_PREREQ (4,0)
  1029. # define signbit(x) __MATH_TG ((x), __builtin_signbit, (x))
  1030. # else
  1031. # define signbit(x) __MATH_TG ((x), __signbit, (x))
  1032. # endif
  1033. /* Return nonzero value if X is not +-Inf or NaN. */
  1034. # if (__GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__) \
  1035. || __glibc_clang_prereq (2,8)
  1036. # define isfinite(x) __builtin_isfinite (x)
  1037. # else
  1038. # define isfinite(x) __MATH_TG ((x), __finite, (x))
  1039. # endif
  1040. /* Return nonzero value if X is neither zero, subnormal, Inf, nor NaN. */
  1041. # if (__GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__) \
  1042. || __glibc_clang_prereq (2,8)
  1043. # define isnormal(x) __builtin_isnormal (x)
  1044. # else
  1045. # define isnormal(x) (fpclassify (x) == FP_NORMAL)
  1046. # endif
  1047. /* Return nonzero value if X is a NaN. We could use `fpclassify' but
  1048. we already have this functions `__isnan' and it is faster. */
  1049. # if (__GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__) \
  1050. || __glibc_clang_prereq (2,8)
  1051. # define isnan(x) __builtin_isnan (x)
  1052. # else
  1053. # define isnan(x) __MATH_TG ((x), __isnan, (x))
  1054. # endif
  1055. /* Return nonzero value if X is positive or negative infinity. */
  1056. # if __HAVE_DISTINCT_FLOAT128 && !__GNUC_PREREQ (7,0) \
  1057. && !defined __SUPPORT_SNAN__ && !defined __cplusplus \
  1058. && !defined __clang__
  1059. /* Since __builtin_isinf_sign is broken for float128 before GCC 7.0,
  1060. use the helper function, __isinff128, with older compilers. This is
  1061. only provided for C mode, because in C++ mode, GCC has no support
  1062. for __builtin_types_compatible_p (and when in C++ mode, this macro is
  1063. not used anyway, because libstdc++ headers undefine it). */
  1064. # define isinf(x) \
  1065. (__builtin_types_compatible_p (__typeof (x), _Float128) \
  1066. ? __isinff128 (x) : __builtin_isinf_sign (x))
  1067. # elif (__GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__) \
  1068. || __glibc_clang_prereq (3,7)
  1069. # define isinf(x) __builtin_isinf_sign (x)
  1070. # else
  1071. # define isinf(x) __MATH_TG ((x), __isinf, (x))
  1072. # endif
  1073. /* Bitmasks for the math_errhandling macro. */
  1074. # define MATH_ERRNO 1 /* errno set by math functions. */
  1075. # define MATH_ERREXCEPT 2 /* Exceptions raised by math functions. */
  1076. /* By default all math functions support both errno and exception handling
  1077. (except for soft floating point implementations which may only support
  1078. errno handling). If errno handling is disabled, exceptions are still
  1079. supported by GLIBC. Set math_errhandling to 0 with -ffast-math (this is
  1080. nonconforming but it is more useful than leaving it undefined). */
  1081. # ifdef __FAST_MATH__
  1082. # define math_errhandling 0
  1083. # elif defined __NO_MATH_ERRNO__
  1084. # define math_errhandling (MATH_ERREXCEPT)
  1085. # else
  1086. # define math_errhandling (MATH_ERRNO | MATH_ERREXCEPT)
  1087. # endif
  1088. #endif /* Use ISO C99. */
  1089. #if __GLIBC_USE (IEC_60559_BFP_EXT_C23)
  1090. # include <bits/iscanonical.h>
  1091. /* Return nonzero value if X is a signaling NaN. */
  1092. # ifndef __cplusplus
  1093. # define issignaling(x) __MATH_TG ((x), __issignaling, (x))
  1094. # else
  1095. /* In C++ mode, __MATH_TG cannot be used, because it relies on
  1096. __builtin_types_compatible_p, which is a C-only builtin. On the
  1097. other hand, overloading provides the means to distinguish between
  1098. the floating-point types. The overloading resolution will match
  1099. the correct parameter (regardless of type qualifiers (i.e.: const
  1100. and volatile)). */
  1101. extern "C++" {
  1102. inline int issignaling (float __val) { return __issignalingf (__val); }
  1103. inline int issignaling (double __val) { return __issignaling (__val); }
  1104. inline int
  1105. issignaling (long double __val)
  1106. {
  1107. # ifdef __NO_LONG_DOUBLE_MATH
  1108. return __issignaling (__val);
  1109. # else
  1110. return __issignalingl (__val);
  1111. # endif
  1112. }
  1113. # if __HAVE_FLOAT128_UNLIKE_LDBL
  1114. /* When using an IEEE 128-bit long double, _Float128 is defined as long double
  1115. in C++. */
  1116. inline int issignaling (_Float128 __val) { return __issignalingf128 (__val); }
  1117. # endif
  1118. } /* extern C++ */
  1119. # endif
  1120. /* Return nonzero value if X is subnormal. */
  1121. # define issubnormal(x) (fpclassify (x) == FP_SUBNORMAL)
  1122. /* Return nonzero value if X is zero. */
  1123. # ifndef __cplusplus
  1124. # ifdef __SUPPORT_SNAN__
  1125. # define iszero(x) (fpclassify (x) == FP_ZERO)
  1126. # else
  1127. # define iszero(x) (((__typeof (x)) (x)) == 0)
  1128. # endif
  1129. # else /* __cplusplus */
  1130. extern "C++" {
  1131. # ifdef __SUPPORT_SNAN__
  1132. inline int
  1133. iszero (float __val)
  1134. {
  1135. return __fpclassifyf (__val) == FP_ZERO;
  1136. }
  1137. inline int
  1138. iszero (double __val)
  1139. {
  1140. return __fpclassify (__val) == FP_ZERO;
  1141. }
  1142. inline int
  1143. iszero (long double __val)
  1144. {
  1145. # ifdef __NO_LONG_DOUBLE_MATH
  1146. return __fpclassify (__val) == FP_ZERO;
  1147. # else
  1148. return __fpclassifyl (__val) == FP_ZERO;
  1149. # endif
  1150. }
  1151. # if __HAVE_FLOAT128_UNLIKE_LDBL
  1152. /* When using an IEEE 128-bit long double, _Float128 is defined as long double
  1153. in C++. */
  1154. inline int
  1155. iszero (_Float128 __val)
  1156. {
  1157. return __fpclassifyf128 (__val) == FP_ZERO;
  1158. }
  1159. # endif
  1160. # else
  1161. template <class __T> inline bool
  1162. iszero (__T __val)
  1163. {
  1164. return __val == 0;
  1165. }
  1166. # endif
  1167. } /* extern C++ */
  1168. # endif /* __cplusplus */
  1169. #endif /* Use IEC_60559_BFP_EXT. */
  1170. #ifdef __USE_XOPEN
  1171. /* X/Open wants another strange constant. */
  1172. # define MAXFLOAT 3.40282347e+38F
  1173. #endif
  1174. /* Some useful constants. */
  1175. #if defined __USE_MISC || defined __USE_XOPEN
  1176. # define M_E 2.7182818284590452354 /* e */
  1177. # define M_LOG2E 1.4426950408889634074 /* log_2 e */
  1178. # define M_LOG10E 0.43429448190325182765 /* log_10 e */
  1179. # define M_LN2 0.69314718055994530942 /* log_e 2 */
  1180. # define M_LN10 2.30258509299404568402 /* log_e 10 */
  1181. # define M_PI 3.14159265358979323846 /* pi */
  1182. # define M_PI_2 1.57079632679489661923 /* pi/2 */
  1183. # define M_PI_4 0.78539816339744830962 /* pi/4 */
  1184. # define M_1_PI 0.31830988618379067154 /* 1/pi */
  1185. # define M_2_PI 0.63661977236758134308 /* 2/pi */
  1186. # define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */
  1187. # define M_SQRT2 1.41421356237309504880 /* sqrt(2) */
  1188. # define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */
  1189. #endif
  1190. /* GNU extension to provide float constants with similar names. */
  1191. #ifdef __USE_GNU
  1192. # define M_Ef 2.7182818284590452354f /* e */
  1193. # define M_LOG2Ef 1.4426950408889634074f /* log_2 e */
  1194. # define M_LOG10Ef 0.43429448190325182765f /* log_10 e */
  1195. # define M_LN2f 0.69314718055994530942f /* log_e 2 */
  1196. # define M_LN10f 2.30258509299404568402f /* log_e 10 */
  1197. # define M_PIf 3.14159265358979323846f /* pi */
  1198. # define M_PI_2f 1.57079632679489661923f /* pi/2 */
  1199. # define M_PI_4f 0.78539816339744830962f /* pi/4 */
  1200. # define M_1_PIf 0.31830988618379067154f /* 1/pi */
  1201. # define M_2_PIf 0.63661977236758134308f /* 2/pi */
  1202. # define M_2_SQRTPIf 1.12837916709551257390f /* 2/sqrt(pi) */
  1203. # define M_SQRT2f 1.41421356237309504880f /* sqrt(2) */
  1204. # define M_SQRT1_2f 0.70710678118654752440f /* 1/sqrt(2) */
  1205. #endif
  1206. /* The above constants are not adequate for computation using `long double's.
  1207. Therefore we provide as an extension constants with similar names as a
  1208. GNU extension. Provide enough digits for the 128-bit IEEE quad. */
  1209. #ifdef __USE_GNU
  1210. # define M_El 2.718281828459045235360287471352662498L /* e */
  1211. # define M_LOG2El 1.442695040888963407359924681001892137L /* log_2 e */
  1212. # define M_LOG10El 0.434294481903251827651128918916605082L /* log_10 e */
  1213. # define M_LN2l 0.693147180559945309417232121458176568L /* log_e 2 */
  1214. # define M_LN10l 2.302585092994045684017991454684364208L /* log_e 10 */
  1215. # define M_PIl 3.141592653589793238462643383279502884L /* pi */
  1216. # define M_PI_2l 1.570796326794896619231321691639751442L /* pi/2 */
  1217. # define M_PI_4l 0.785398163397448309615660845819875721L /* pi/4 */
  1218. # define M_1_PIl 0.318309886183790671537767526745028724L /* 1/pi */
  1219. # define M_2_PIl 0.636619772367581343075535053490057448L /* 2/pi */
  1220. # define M_2_SQRTPIl 1.128379167095512573896158903121545172L /* 2/sqrt(pi) */
  1221. # define M_SQRT2l 1.414213562373095048801688724209698079L /* sqrt(2) */
  1222. # define M_SQRT1_2l 0.707106781186547524400844362104849039L /* 1/sqrt(2) */
  1223. #endif
  1224. #if __HAVE_FLOAT16 && defined __USE_GNU
  1225. # define M_Ef16 __f16 (2.718281828459045235360287471352662498) /* e */
  1226. # define M_LOG2Ef16 __f16 (1.442695040888963407359924681001892137) /* log_2 e */
  1227. # define M_LOG10Ef16 __f16 (0.434294481903251827651128918916605082) /* log_10 e */
  1228. # define M_LN2f16 __f16 (0.693147180559945309417232121458176568) /* log_e 2 */
  1229. # define M_LN10f16 __f16 (2.302585092994045684017991454684364208) /* log_e 10 */
  1230. # define M_PIf16 __f16 (3.141592653589793238462643383279502884) /* pi */
  1231. # define M_PI_2f16 __f16 (1.570796326794896619231321691639751442) /* pi/2 */
  1232. # define M_PI_4f16 __f16 (0.785398163397448309615660845819875721) /* pi/4 */
  1233. # define M_1_PIf16 __f16 (0.318309886183790671537767526745028724) /* 1/pi */
  1234. # define M_2_PIf16 __f16 (0.636619772367581343075535053490057448) /* 2/pi */
  1235. # define M_2_SQRTPIf16 __f16 (1.128379167095512573896158903121545172) /* 2/sqrt(pi) */
  1236. # define M_SQRT2f16 __f16 (1.414213562373095048801688724209698079) /* sqrt(2) */
  1237. # define M_SQRT1_2f16 __f16 (0.707106781186547524400844362104849039) /* 1/sqrt(2) */
  1238. #endif
  1239. #if __HAVE_FLOAT32 && defined __USE_GNU
  1240. # define M_Ef32 __f32 (2.718281828459045235360287471352662498) /* e */
  1241. # define M_LOG2Ef32 __f32 (1.442695040888963407359924681001892137) /* log_2 e */
  1242. # define M_LOG10Ef32 __f32 (0.434294481903251827651128918916605082) /* log_10 e */
  1243. # define M_LN2f32 __f32 (0.693147180559945309417232121458176568) /* log_e 2 */
  1244. # define M_LN10f32 __f32 (2.302585092994045684017991454684364208) /* log_e 10 */
  1245. # define M_PIf32 __f32 (3.141592653589793238462643383279502884) /* pi */
  1246. # define M_PI_2f32 __f32 (1.570796326794896619231321691639751442) /* pi/2 */
  1247. # define M_PI_4f32 __f32 (0.785398163397448309615660845819875721) /* pi/4 */
  1248. # define M_1_PIf32 __f32 (0.318309886183790671537767526745028724) /* 1/pi */
  1249. # define M_2_PIf32 __f32 (0.636619772367581343075535053490057448) /* 2/pi */
  1250. # define M_2_SQRTPIf32 __f32 (1.128379167095512573896158903121545172) /* 2/sqrt(pi) */
  1251. # define M_SQRT2f32 __f32 (1.414213562373095048801688724209698079) /* sqrt(2) */
  1252. # define M_SQRT1_2f32 __f32 (0.707106781186547524400844362104849039) /* 1/sqrt(2) */
  1253. #endif
  1254. #if __HAVE_FLOAT64 && defined __USE_GNU
  1255. # define M_Ef64 __f64 (2.718281828459045235360287471352662498) /* e */
  1256. # define M_LOG2Ef64 __f64 (1.442695040888963407359924681001892137) /* log_2 e */
  1257. # define M_LOG10Ef64 __f64 (0.434294481903251827651128918916605082) /* log_10 e */
  1258. # define M_LN2f64 __f64 (0.693147180559945309417232121458176568) /* log_e 2 */
  1259. # define M_LN10f64 __f64 (2.302585092994045684017991454684364208) /* log_e 10 */
  1260. # define M_PIf64 __f64 (3.141592653589793238462643383279502884) /* pi */
  1261. # define M_PI_2f64 __f64 (1.570796326794896619231321691639751442) /* pi/2 */
  1262. # define M_PI_4f64 __f64 (0.785398163397448309615660845819875721) /* pi/4 */
  1263. # define M_1_PIf64 __f64 (0.318309886183790671537767526745028724) /* 1/pi */
  1264. # define M_2_PIf64 __f64 (0.636619772367581343075535053490057448) /* 2/pi */
  1265. # define M_2_SQRTPIf64 __f64 (1.128379167095512573896158903121545172) /* 2/sqrt(pi) */
  1266. # define M_SQRT2f64 __f64 (1.414213562373095048801688724209698079) /* sqrt(2) */
  1267. # define M_SQRT1_2f64 __f64 (0.707106781186547524400844362104849039) /* 1/sqrt(2) */
  1268. #endif
  1269. #if __HAVE_FLOAT128 && defined __USE_GNU
  1270. # define M_Ef128 __f128 (2.718281828459045235360287471352662498) /* e */
  1271. # define M_LOG2Ef128 __f128 (1.442695040888963407359924681001892137) /* log_2 e */
  1272. # define M_LOG10Ef128 __f128 (0.434294481903251827651128918916605082) /* log_10 e */
  1273. # define M_LN2f128 __f128 (0.693147180559945309417232121458176568) /* log_e 2 */
  1274. # define M_LN10f128 __f128 (2.302585092994045684017991454684364208) /* log_e 10 */
  1275. # define M_PIf128 __f128 (3.141592653589793238462643383279502884) /* pi */
  1276. # define M_PI_2f128 __f128 (1.570796326794896619231321691639751442) /* pi/2 */
  1277. # define M_PI_4f128 __f128 (0.785398163397448309615660845819875721) /* pi/4 */
  1278. # define M_1_PIf128 __f128 (0.318309886183790671537767526745028724) /* 1/pi */
  1279. # define M_2_PIf128 __f128 (0.636619772367581343075535053490057448) /* 2/pi */
  1280. # define M_2_SQRTPIf128 __f128 (1.128379167095512573896158903121545172) /* 2/sqrt(pi) */
  1281. # define M_SQRT2f128 __f128 (1.414213562373095048801688724209698079) /* sqrt(2) */
  1282. # define M_SQRT1_2f128 __f128 (0.707106781186547524400844362104849039) /* 1/sqrt(2) */
  1283. #endif
  1284. #if __HAVE_FLOAT32X && defined __USE_GNU
  1285. # define M_Ef32x __f32x (2.718281828459045235360287471352662498) /* e */
  1286. # define M_LOG2Ef32x __f32x (1.442695040888963407359924681001892137) /* log_2 e */
  1287. # define M_LOG10Ef32x __f32x (0.434294481903251827651128918916605082) /* log_10 e */
  1288. # define M_LN2f32x __f32x (0.693147180559945309417232121458176568) /* log_e 2 */
  1289. # define M_LN10f32x __f32x (2.302585092994045684017991454684364208) /* log_e 10 */
  1290. # define M_PIf32x __f32x (3.141592653589793238462643383279502884) /* pi */
  1291. # define M_PI_2f32x __f32x (1.570796326794896619231321691639751442) /* pi/2 */
  1292. # define M_PI_4f32x __f32x (0.785398163397448309615660845819875721) /* pi/4 */
  1293. # define M_1_PIf32x __f32x (0.318309886183790671537767526745028724) /* 1/pi */
  1294. # define M_2_PIf32x __f32x (0.636619772367581343075535053490057448) /* 2/pi */
  1295. # define M_2_SQRTPIf32x __f32x (1.128379167095512573896158903121545172) /* 2/sqrt(pi) */
  1296. # define M_SQRT2f32x __f32x (1.414213562373095048801688724209698079) /* sqrt(2) */
  1297. # define M_SQRT1_2f32x __f32x (0.707106781186547524400844362104849039) /* 1/sqrt(2) */
  1298. #endif
  1299. #if __HAVE_FLOAT64X && defined __USE_GNU
  1300. # define M_Ef64x __f64x (2.718281828459045235360287471352662498) /* e */
  1301. # define M_LOG2Ef64x __f64x (1.442695040888963407359924681001892137) /* log_2 e */
  1302. # define M_LOG10Ef64x __f64x (0.434294481903251827651128918916605082) /* log_10 e */
  1303. # define M_LN2f64x __f64x (0.693147180559945309417232121458176568) /* log_e 2 */
  1304. # define M_LN10f64x __f64x (2.302585092994045684017991454684364208) /* log_e 10 */
  1305. # define M_PIf64x __f64x (3.141592653589793238462643383279502884) /* pi */
  1306. # define M_PI_2f64x __f64x (1.570796326794896619231321691639751442) /* pi/2 */
  1307. # define M_PI_4f64x __f64x (0.785398163397448309615660845819875721) /* pi/4 */
  1308. # define M_1_PIf64x __f64x (0.318309886183790671537767526745028724) /* 1/pi */
  1309. # define M_2_PIf64x __f64x (0.636619772367581343075535053490057448) /* 2/pi */
  1310. # define M_2_SQRTPIf64x __f64x (1.128379167095512573896158903121545172) /* 2/sqrt(pi) */
  1311. # define M_SQRT2f64x __f64x (1.414213562373095048801688724209698079) /* sqrt(2) */
  1312. # define M_SQRT1_2f64x __f64x (0.707106781186547524400844362104849039) /* 1/sqrt(2) */
  1313. #endif
  1314. #if __HAVE_FLOAT128X && defined __USE_GNU
  1315. # error "M_* values needed for _Float128x"
  1316. #endif
  1317. #ifdef __USE_ISOC99
  1318. # if __GNUC_PREREQ (3, 1) && !defined __clang__
  1319. /* ISO C99 defines some macros to compare number while taking care for
  1320. unordered numbers. Many FPUs provide special instructions to support
  1321. these operations. Generic support in GCC for these as builtins went
  1322. in 2.97, but not all cpus added their patterns until 3.1. Therefore
  1323. we enable the builtins from 3.1 onwards and use a generic implementation
  1324. otherwise. */
  1325. # define isgreater(x, y) __builtin_isgreater(x, y)
  1326. # define isgreaterequal(x, y) __builtin_isgreaterequal(x, y)
  1327. # define isless(x, y) __builtin_isless(x, y)
  1328. # define islessequal(x, y) __builtin_islessequal(x, y)
  1329. # define islessgreater(x, y) __builtin_islessgreater(x, y)
  1330. # define isunordered(x, y) __builtin_isunordered(x, y)
  1331. # else
  1332. # define isgreater(x, y) \
  1333. (__extension__ ({ __typeof__ (x) __x = (x); __typeof__ (y) __y = (y); \
  1334. !isunordered (__x, __y) && __x > __y; }))
  1335. # define isgreaterequal(x, y) \
  1336. (__extension__ ({ __typeof__ (x) __x = (x); __typeof__ (y) __y = (y); \
  1337. !isunordered (__x, __y) && __x >= __y; }))
  1338. # define isless(x, y) \
  1339. (__extension__ ({ __typeof__ (x) __x = (x); __typeof__ (y) __y = (y); \
  1340. !isunordered (__x, __y) && __x < __y; }))
  1341. # define islessequal(x, y) \
  1342. (__extension__ ({ __typeof__ (x) __x = (x); __typeof__ (y) __y = (y); \
  1343. !isunordered (__x, __y) && __x <= __y; }))
  1344. # define islessgreater(x, y) \
  1345. (__extension__ ({ __typeof__ (x) __x = (x); __typeof__ (y) __y = (y); \
  1346. !isunordered (__x, __y) && __x != __y; }))
  1347. /* isunordered must always check both operands first for signaling NaNs. */
  1348. # define isunordered(x, y) \
  1349. (__extension__ ({ __typeof__ (x) __u = (x); __typeof__ (y) __v = (y); \
  1350. __u != __v && (__u != __u || __v != __v); }))
  1351. # endif
  1352. #endif
  1353. #if __GLIBC_USE (IEC_60559_BFP_EXT_C23)
  1354. /* An expression whose type has the widest of the evaluation formats
  1355. of X and Y (which are of floating-point types). */
  1356. # if __FLT_EVAL_METHOD__ == 2 || __FLT_EVAL_METHOD__ > 64
  1357. # define __MATH_EVAL_FMT2(x, y) ((x) + (y) + 0.0L)
  1358. # elif __FLT_EVAL_METHOD__ == 1 || __FLT_EVAL_METHOD__ > 32
  1359. # define __MATH_EVAL_FMT2(x, y) ((x) + (y) + 0.0)
  1360. # elif __FLT_EVAL_METHOD__ == 0 || __FLT_EVAL_METHOD__ == 32
  1361. # define __MATH_EVAL_FMT2(x, y) ((x) + (y) + 0.0f)
  1362. # else
  1363. # define __MATH_EVAL_FMT2(x, y) ((x) + (y))
  1364. # endif
  1365. /* Return X == Y but raising "invalid" and setting errno if X or Y is
  1366. a NaN. */
  1367. # if !defined __cplusplus || (__cplusplus < 201103L && !defined __GNUC__)
  1368. # define iseqsig(x, y) \
  1369. __MATH_TG (__MATH_EVAL_FMT2 (x, y), __iseqsig, ((x), (y)))
  1370. # else
  1371. /* In C++ mode, __MATH_TG cannot be used, because it relies on
  1372. __builtin_types_compatible_p, which is a C-only builtin. Moreover,
  1373. the comparison macros from ISO C take two floating-point arguments,
  1374. which need not have the same type. Choosing what underlying function
  1375. to call requires evaluating the formats of the arguments, then
  1376. selecting which is wider. The macro __MATH_EVAL_FMT2 provides this
  1377. information, however, only the type of the macro expansion is
  1378. relevant (actually evaluating the expression would be incorrect).
  1379. Thus, the type is used as a template parameter for __iseqsig_type,
  1380. which calls the appropriate underlying function. */
  1381. extern "C++" {
  1382. template<typename> struct __iseqsig_type;
  1383. template<> struct __iseqsig_type<float>
  1384. {
  1385. static int __call (float __x, float __y) throw ()
  1386. {
  1387. return __iseqsigf (__x, __y);
  1388. }
  1389. };
  1390. template<> struct __iseqsig_type<double>
  1391. {
  1392. static int __call (double __x, double __y) throw ()
  1393. {
  1394. return __iseqsig (__x, __y);
  1395. }
  1396. };
  1397. template<> struct __iseqsig_type<long double>
  1398. {
  1399. static int __call (long double __x, long double __y) throw ()
  1400. {
  1401. # ifndef __NO_LONG_DOUBLE_MATH
  1402. return __iseqsigl (__x, __y);
  1403. # else
  1404. return __iseqsig (__x, __y);
  1405. # endif
  1406. }
  1407. };
  1408. # if __HAVE_FLOAT32 && __GNUC_PREREQ (13, 0)
  1409. template<> struct __iseqsig_type<_Float32>
  1410. {
  1411. static int __call (_Float32 __x, _Float32 __y) throw ()
  1412. {
  1413. return __iseqsigf (__x, __y);
  1414. }
  1415. };
  1416. # endif
  1417. # if __HAVE_FLOAT64 && __GNUC_PREREQ (13, 0)
  1418. template<> struct __iseqsig_type<_Float64>
  1419. {
  1420. static int __call (_Float64 __x, _Float64 __y) throw ()
  1421. {
  1422. return __iseqsig (__x, __y);
  1423. }
  1424. };
  1425. # endif
  1426. # if __HAVE_FLOAT128_UNLIKE_LDBL || (__HAVE_FLOAT128 && __GNUC_PREREQ (13, 0))
  1427. /* When using an IEEE 128-bit long double, _Float128 is defined as long double
  1428. in C++. */
  1429. template<> struct __iseqsig_type<_Float128>
  1430. {
  1431. static int __call (_Float128 __x, _Float128 __y) throw ()
  1432. {
  1433. # if __HAVE_FLOAT128_UNLIKE_LDBL
  1434. return __iseqsigf128 (__x, __y);
  1435. # else
  1436. return __iseqsigl (__x, __y);
  1437. # endif
  1438. }
  1439. };
  1440. # endif
  1441. # if __HAVE_FLOAT32X && __GNUC_PREREQ (13, 0)
  1442. template<> struct __iseqsig_type<_Float32x>
  1443. {
  1444. static int __call (_Float32x __x, _Float32x __y) throw ()
  1445. {
  1446. return __iseqsig (__x, __y);
  1447. }
  1448. };
  1449. # endif
  1450. # if __HAVE_FLOAT64X && __GNUC_PREREQ (13, 0)
  1451. template<> struct __iseqsig_type<_Float64x>
  1452. {
  1453. static int __call (_Float64x __x, _Float64x __y) throw ()
  1454. {
  1455. # if __HAVE_FLOAT64X_LONG_DOUBLE
  1456. return __iseqsigl (__x, __y);
  1457. # else
  1458. return __iseqsigf128 (__x, __y);
  1459. # endif
  1460. }
  1461. };
  1462. # endif
  1463. template<typename _T1, typename _T2>
  1464. inline int
  1465. iseqsig (_T1 __x, _T2 __y) throw ()
  1466. {
  1467. # if __cplusplus >= 201103L
  1468. typedef decltype (__MATH_EVAL_FMT2 (__x, __y)) _T3;
  1469. # else
  1470. typedef __typeof (__MATH_EVAL_FMT2 (__x, __y)) _T3;
  1471. # endif
  1472. return __iseqsig_type<_T3>::__call (__x, __y);
  1473. }
  1474. } /* extern "C++" */
  1475. # endif /* __cplusplus */
  1476. #endif
  1477. __END_DECLS
  1478. #endif /* math.h */