math.h 52 KB

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