math.h 45 KB

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