math.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  1. /* Declarations for math functions.
  2. Copyright (C) 1991-2017 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. <http://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. __BEGIN_DECLS
  23. /* Get definitions of __intmax_t and __uintmax_t. */
  24. #include <bits/types.h>
  25. /* Get machine-dependent vector math functions declarations. */
  26. #include <bits/math-vector.h>
  27. /* Get machine-dependent HUGE_VAL value (returned on overflow).
  28. On all IEEE754 machines, this is +Infinity. */
  29. #include <bits/huge_val.h>
  30. #ifdef __USE_ISOC99
  31. # include <bits/huge_valf.h>
  32. # include <bits/huge_vall.h>
  33. /* Get machine-dependent INFINITY value. */
  34. # include <bits/inf.h>
  35. /* Get machine-dependent NAN value (returned for some domain errors). */
  36. # include <bits/nan.h>
  37. #endif /* __USE_ISOC99 */
  38. #if __GLIBC_USE (IEC_60559_BFP_EXT)
  39. /* Signaling NaN macros, if supported. */
  40. # if __GNUC_PREREQ (3, 3)
  41. # define SNANF (__builtin_nansf (""))
  42. # define SNAN (__builtin_nans (""))
  43. # define SNANL (__builtin_nansl (""))
  44. # endif
  45. #endif
  46. /* Get __GLIBC_FLT_EVAL_METHOD. */
  47. #include <bits/flt-eval-method.h>
  48. #ifdef __USE_ISOC99
  49. /* Define the following typedefs.
  50. float_t floating-point type at least as wide as `float' used
  51. to evaluate `float' expressions
  52. double_t floating-point type at least as wide as `double' used
  53. to evaluate `double' expressions
  54. */
  55. # if __GLIBC_FLT_EVAL_METHOD == 0 || __GLIBC_FLT_EVAL_METHOD == 16
  56. typedef float float_t;
  57. typedef double double_t;
  58. # elif __GLIBC_FLT_EVAL_METHOD == 1
  59. typedef double float_t;
  60. typedef double double_t;
  61. # elif __GLIBC_FLT_EVAL_METHOD == 2
  62. typedef long double float_t;
  63. typedef long double double_t;
  64. # elif __GLIBC_FLT_EVAL_METHOD == 32
  65. typedef _Float32 float_t;
  66. typedef double double_t;
  67. # elif __GLIBC_FLT_EVAL_METHOD == 33
  68. typedef _Float32x float_t;
  69. typedef _Float32x double_t;
  70. # elif __GLIBC_FLT_EVAL_METHOD == 64
  71. typedef _Float64 float_t;
  72. typedef _Float64 double_t;
  73. # elif __GLIBC_FLT_EVAL_METHOD == 65
  74. typedef _Float64x float_t;
  75. typedef _Float64x double_t;
  76. # elif __GLIBC_FLT_EVAL_METHOD == 128
  77. typedef _Float128 float_t;
  78. typedef _Float128 double_t;
  79. # elif __GLIBC_FLT_EVAL_METHOD == 129
  80. typedef _Float128x float_t;
  81. typedef _Float128x double_t;
  82. # else
  83. # error "Unknown __GLIBC_FLT_EVAL_METHOD"
  84. # endif
  85. #endif
  86. /* Define macros for the return values of ilogb and llogb, based on
  87. __FP_LOGB0_IS_MIN and __FP_LOGBNAN_IS_MIN.
  88. FP_ILOGB0 Expands to a value returned by `ilogb (0.0)'.
  89. FP_ILOGBNAN Expands to a value returned by `ilogb (NAN)'.
  90. FP_LLOGB0 Expands to a value returned by `llogb (0.0)'.
  91. FP_LLOGBNAN Expands to a value returned by `llogb (NAN)'.
  92. */
  93. #include <bits/fp-logb.h>
  94. #ifdef __USE_ISOC99
  95. # if __FP_LOGB0_IS_MIN
  96. # define FP_ILOGB0 (-2147483647 - 1)
  97. # else
  98. # define FP_ILOGB0 (-2147483647)
  99. # endif
  100. # if __FP_LOGBNAN_IS_MIN
  101. # define FP_ILOGBNAN (-2147483647 - 1)
  102. # else
  103. # define FP_ILOGBNAN 2147483647
  104. # endif
  105. #endif
  106. #if __GLIBC_USE (IEC_60559_BFP_EXT)
  107. # if __WORDSIZE == 32
  108. # define __FP_LONG_MAX 0x7fffffffL
  109. # else
  110. # define __FP_LONG_MAX 0x7fffffffffffffffL
  111. # endif
  112. # if __FP_LOGB0_IS_MIN
  113. # define FP_LLOGB0 (-__FP_LONG_MAX - 1)
  114. # else
  115. # define FP_LLOGB0 (-__FP_LONG_MAX)
  116. # endif
  117. # if __FP_LOGBNAN_IS_MIN
  118. # define FP_LLOGBNAN (-__FP_LONG_MAX - 1)
  119. # else
  120. # define FP_LLOGBNAN __FP_LONG_MAX
  121. # endif
  122. #endif
  123. /* Get the architecture specific values describing the floating-point
  124. evaluation. The following symbols will get defined:
  125. FP_FAST_FMA
  126. FP_FAST_FMAF
  127. FP_FAST_FMAL
  128. If defined it indicates that the `fma' function
  129. generally executes about as fast as a multiply and an add.
  130. This macro is defined only iff the `fma' function is
  131. implemented directly with a hardware multiply-add instructions.
  132. */
  133. #include <bits/fp-fast.h>
  134. #if __GLIBC_USE (IEC_60559_BFP_EXT)
  135. /* Rounding direction macros for fromfp functions. */
  136. enum
  137. {
  138. FP_INT_UPWARD =
  139. # define FP_INT_UPWARD 0
  140. FP_INT_UPWARD,
  141. FP_INT_DOWNWARD =
  142. # define FP_INT_DOWNWARD 1
  143. FP_INT_DOWNWARD,
  144. FP_INT_TOWARDZERO =
  145. # define FP_INT_TOWARDZERO 2
  146. FP_INT_TOWARDZERO,
  147. FP_INT_TONEARESTFROMZERO =
  148. # define FP_INT_TONEARESTFROMZERO 3
  149. FP_INT_TONEARESTFROMZERO,
  150. FP_INT_TONEAREST =
  151. # define FP_INT_TONEAREST 4
  152. FP_INT_TONEAREST,
  153. };
  154. #endif
  155. /* The file <bits/mathcalls.h> contains the prototypes for all the
  156. actual math functions. These macros are used for those prototypes,
  157. so we can easily declare each function as both `name' and `__name',
  158. and can declare the float versions `namef' and `__namef'. */
  159. #define __SIMD_DECL(function) __CONCAT (__DECL_SIMD_, function)
  160. #define __MATHCALL_VEC(function, suffix, args) \
  161. __SIMD_DECL (__MATH_PRECNAME (function, suffix)) \
  162. __MATHCALL (function, suffix, args)
  163. #define __MATHDECL_VEC(type, function,suffix, args) \
  164. __SIMD_DECL (__MATH_PRECNAME (function, suffix)) \
  165. __MATHDECL(type, function,suffix, args)
  166. #define __MATHCALL(function,suffix, args) \
  167. __MATHDECL (_Mdouble_,function,suffix, args)
  168. #define __MATHDECL(type, function,suffix, args) \
  169. __MATHDECL_1(type, function,suffix, args); \
  170. __MATHDECL_1(type, __CONCAT(__,function),suffix, args)
  171. #define __MATHCALLX(function,suffix, args, attrib) \
  172. __MATHDECLX (_Mdouble_,function,suffix, args, attrib)
  173. #define __MATHDECLX(type, function,suffix, args, attrib) \
  174. __MATHDECL_1(type, function,suffix, args) __attribute__ (attrib); \
  175. __MATHDECL_1(type, __CONCAT(__,function),suffix, args) __attribute__ (attrib)
  176. #define __MATHDECL_1(type, function,suffix, args) \
  177. extern type __MATH_PRECNAME(function,suffix) args __THROW
  178. #define _Mdouble_ double
  179. #define __MATH_PRECNAME(name,r) __CONCAT(name,r)
  180. #define __MATH_DECLARING_DOUBLE 1
  181. #define _Mdouble_BEGIN_NAMESPACE __BEGIN_NAMESPACE_STD
  182. #define _Mdouble_END_NAMESPACE __END_NAMESPACE_STD
  183. #include <bits/mathcalls.h>
  184. #undef _Mdouble_
  185. #undef _Mdouble_BEGIN_NAMESPACE
  186. #undef _Mdouble_END_NAMESPACE
  187. #undef __MATH_PRECNAME
  188. #undef __MATH_DECLARING_DOUBLE
  189. #ifdef __USE_ISOC99
  190. /* Include the file of declarations again, this time using `float'
  191. instead of `double' and appending f to each function name. */
  192. # ifndef _Mfloat_
  193. # define _Mfloat_ float
  194. # endif
  195. # define _Mdouble_ _Mfloat_
  196. # define __MATH_PRECNAME(name,r) name##f##r
  197. # define __MATH_DECLARING_DOUBLE 0
  198. # define _Mdouble_BEGIN_NAMESPACE __BEGIN_NAMESPACE_C99
  199. # define _Mdouble_END_NAMESPACE __END_NAMESPACE_C99
  200. # include <bits/mathcalls.h>
  201. # undef _Mdouble_
  202. # undef _Mdouble_BEGIN_NAMESPACE
  203. # undef _Mdouble_END_NAMESPACE
  204. # undef __MATH_PRECNAME
  205. # undef __MATH_DECLARING_DOUBLE
  206. # if !(defined __NO_LONG_DOUBLE_MATH && defined _LIBC) \
  207. || defined __LDBL_COMPAT \
  208. || defined _LIBC_TEST
  209. # ifdef __LDBL_COMPAT
  210. # ifdef __USE_ISOC99
  211. extern float __nldbl_nexttowardf (float __x, long double __y)
  212. __THROW __attribute__ ((__const__));
  213. # ifdef __REDIRECT_NTH
  214. extern float __REDIRECT_NTH (nexttowardf, (float __x, long double __y),
  215. __nldbl_nexttowardf)
  216. __attribute__ ((__const__));
  217. extern double __REDIRECT_NTH (nexttoward, (double __x, long double __y),
  218. nextafter) __attribute__ ((__const__));
  219. extern long double __REDIRECT_NTH (nexttowardl,
  220. (long double __x, long double __y),
  221. nextafter) __attribute__ ((__const__));
  222. # endif
  223. # endif
  224. # undef __MATHDECL_1
  225. # define __MATHDECL_2(type, function,suffix, args, alias) \
  226. extern type __REDIRECT_NTH(__MATH_PRECNAME(function,suffix), \
  227. args, alias)
  228. # define __MATHDECL_1(type, function,suffix, args) \
  229. __MATHDECL_2(type, function,suffix, args, __CONCAT(function,suffix))
  230. # endif
  231. /* Include the file of declarations again, this time using `long double'
  232. instead of `double' and appending l to each function name. */
  233. # ifndef _Mlong_double_
  234. # define _Mlong_double_ long double
  235. # endif
  236. # define _Mdouble_ _Mlong_double_
  237. # define __MATH_PRECNAME(name,r) name##l##r
  238. # define __MATH_DECLARING_DOUBLE 0
  239. # define _Mdouble_BEGIN_NAMESPACE __BEGIN_NAMESPACE_C99
  240. # define _Mdouble_END_NAMESPACE __END_NAMESPACE_C99
  241. # define __MATH_DECLARE_LDOUBLE 1
  242. # include <bits/mathcalls.h>
  243. # undef _Mdouble_
  244. # undef _Mdouble_BEGIN_NAMESPACE
  245. # undef _Mdouble_END_NAMESPACE
  246. # undef __MATH_PRECNAME
  247. # undef __MATH_DECLARING_DOUBLE
  248. # endif /* !(__NO_LONG_DOUBLE_MATH && _LIBC) || __LDBL_COMPAT */
  249. #endif /* Use ISO C99. */
  250. #undef __MATHDECL_1
  251. #undef __MATHDECL
  252. #undef __MATHCALL
  253. #if defined __USE_MISC || defined __USE_XOPEN
  254. /* This variable is used by `gamma' and `lgamma'. */
  255. extern int signgam;
  256. #endif
  257. /* Depending on the type of TG_ARG, call an appropriately suffixed
  258. version of FUNC with arguments (including parentheses) ARGS.
  259. Suffixed functions may not exist for long double if it has the same
  260. format as double, or for other types with the same format as float,
  261. double or long double. The behavior is undefined if the argument
  262. does not have a real floating type. The definition may use a
  263. conditional expression, so all suffixed versions of FUNC must
  264. return the same type (FUNC may include a cast if necessary rather
  265. than being a single identifier). */
  266. #ifdef __NO_LONG_DOUBLE_MATH
  267. # define __MATH_TG(TG_ARG, FUNC, ARGS) \
  268. (sizeof (TG_ARG) == sizeof (float) ? FUNC ## f ARGS : FUNC ARGS)
  269. #else
  270. # define __MATH_TG(TG_ARG, FUNC, ARGS) \
  271. (sizeof (TG_ARG) == sizeof (float) \
  272. ? FUNC ## f ARGS \
  273. : sizeof (TG_ARG) == sizeof (double) \
  274. ? FUNC ARGS \
  275. : FUNC ## l ARGS)
  276. #endif
  277. /* ISO C99 defines some generic macros which work on any data type. */
  278. #ifdef __USE_ISOC99
  279. /* All floating-point numbers can be put in one of these categories. */
  280. enum
  281. {
  282. FP_NAN =
  283. # define FP_NAN 0
  284. FP_NAN,
  285. FP_INFINITE =
  286. # define FP_INFINITE 1
  287. FP_INFINITE,
  288. FP_ZERO =
  289. # define FP_ZERO 2
  290. FP_ZERO,
  291. FP_SUBNORMAL =
  292. # define FP_SUBNORMAL 3
  293. FP_SUBNORMAL,
  294. FP_NORMAL =
  295. # define FP_NORMAL 4
  296. FP_NORMAL
  297. };
  298. /* GCC bug 66462 means we cannot use the math builtins with -fsignaling-nan,
  299. so disable builtins if this is enabled. When fixed in a newer GCC,
  300. the __SUPPORT_SNAN__ check may be skipped for those versions. */
  301. /* Return number of classification appropriate for X. */
  302. # if __GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__ \
  303. && !defined __OPTIMIZE_SIZE__
  304. # define fpclassify(x) __builtin_fpclassify (FP_NAN, FP_INFINITE, \
  305. FP_NORMAL, FP_SUBNORMAL, FP_ZERO, x)
  306. # else
  307. # define fpclassify(x) __MATH_TG ((x), __fpclassify, (x))
  308. # endif
  309. /* Return nonzero value if sign of X is negative. */
  310. # if __GNUC_PREREQ (4,0)
  311. # define signbit(x) __MATH_TG ((x), __builtin_signbit, (x))
  312. # else
  313. # define signbit(x) __MATH_TG ((x), __signbit, (x))
  314. # endif
  315. /* Return nonzero value if X is not +-Inf or NaN. */
  316. # if __GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__
  317. # define isfinite(x) __builtin_isfinite (x)
  318. # else
  319. # define isfinite(x) __MATH_TG ((x), __finite, (x))
  320. # endif
  321. /* Return nonzero value if X is neither zero, subnormal, Inf, nor NaN. */
  322. # if __GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__
  323. # define isnormal(x) __builtin_isnormal (x)
  324. # else
  325. # define isnormal(x) (fpclassify (x) == FP_NORMAL)
  326. # endif
  327. /* Return nonzero value if X is a NaN. We could use `fpclassify' but
  328. we already have this functions `__isnan' and it is faster. */
  329. # if __GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__
  330. # define isnan(x) __builtin_isnan (x)
  331. # else
  332. # define isnan(x) __MATH_TG ((x), __isnan, (x))
  333. # endif
  334. /* Return nonzero value if X is positive or negative infinity. */
  335. # if __GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__
  336. # define isinf(x) __builtin_isinf_sign (x)
  337. # else
  338. # define isinf(x) __MATH_TG ((x), __isinf, (x))
  339. # endif
  340. /* Bitmasks for the math_errhandling macro. */
  341. # define MATH_ERRNO 1 /* errno set by math functions. */
  342. # define MATH_ERREXCEPT 2 /* Exceptions raised by math functions. */
  343. /* By default all functions support both errno and exception handling.
  344. In gcc's fast math mode and if inline functions are defined this
  345. might not be true. */
  346. # ifndef __FAST_MATH__
  347. # define math_errhandling (MATH_ERRNO | MATH_ERREXCEPT)
  348. # endif
  349. #endif /* Use ISO C99. */
  350. #if __GLIBC_USE (IEC_60559_BFP_EXT)
  351. # include <bits/iscanonical.h>
  352. /* Return nonzero value if X is a signaling NaN. */
  353. # define issignaling(x) __MATH_TG ((x), __issignaling, (x))
  354. /* Return nonzero value if X is subnormal. */
  355. # define issubnormal(x) (fpclassify (x) == FP_SUBNORMAL)
  356. /* Return nonzero value if X is zero. */
  357. # ifndef __cplusplus
  358. # ifdef __SUPPORT_SNAN__
  359. # define iszero(x) (fpclassify (x) == FP_ZERO)
  360. # else
  361. # define iszero(x) (((__typeof (x)) (x)) == 0)
  362. # endif
  363. # else /* __cplusplus */
  364. extern "C++" {
  365. template <class __T> inline bool
  366. iszero (__T __val)
  367. {
  368. # ifdef __SUPPORT_SNAN__
  369. return fpclassify (__val) == FP_ZERO;
  370. # else
  371. return __val == 0;
  372. # endif
  373. }
  374. } /* extern C++ */
  375. # endif /* __cplusplus */
  376. #endif /* Use IEC_60559_BFP_EXT. */
  377. #ifdef __USE_MISC
  378. /* Support for various different standard error handling behaviors. */
  379. typedef enum
  380. {
  381. _IEEE_ = -1, /* According to IEEE 754/IEEE 854. */
  382. _SVID_, /* According to System V, release 4. */
  383. _XOPEN_, /* Nowadays also Unix98. */
  384. _POSIX_,
  385. _ISOC_ /* Actually this is ISO C99. */
  386. } _LIB_VERSION_TYPE;
  387. /* This variable can be changed at run-time to any of the values above to
  388. affect floating point error handling behavior (it may also be necessary
  389. to change the hardware FPU exception settings). */
  390. extern _LIB_VERSION_TYPE _LIB_VERSION;
  391. #endif
  392. #ifdef __USE_MISC
  393. /* In SVID error handling, `matherr' is called with this description
  394. of the exceptional condition.
  395. We have a problem when using C++ since `exception' is a reserved
  396. name in C++. */
  397. # ifdef __cplusplus
  398. struct __exception
  399. # else
  400. struct exception
  401. # endif
  402. {
  403. int type;
  404. char *name;
  405. double arg1;
  406. double arg2;
  407. double retval;
  408. };
  409. # ifdef __cplusplus
  410. extern int matherr (struct __exception *__exc) throw ();
  411. # else
  412. extern int matherr (struct exception *__exc);
  413. # endif
  414. # define X_TLOSS 1.41484755040568800000e+16
  415. /* Types of exceptions in the `type' field. */
  416. # define DOMAIN 1
  417. # define SING 2
  418. # define OVERFLOW 3
  419. # define UNDERFLOW 4
  420. # define TLOSS 5
  421. # define PLOSS 6
  422. /* SVID mode specifies returning this large value instead of infinity. */
  423. # define HUGE 3.40282347e+38F
  424. #else /* !Misc. */
  425. # ifdef __USE_XOPEN
  426. /* X/Open wants another strange constant. */
  427. # define MAXFLOAT 3.40282347e+38F
  428. # endif
  429. #endif /* Misc. */
  430. /* Some useful constants. */
  431. #if defined __USE_MISC || defined __USE_XOPEN
  432. # define M_E 2.7182818284590452354 /* e */
  433. # define M_LOG2E 1.4426950408889634074 /* log_2 e */
  434. # define M_LOG10E 0.43429448190325182765 /* log_10 e */
  435. # define M_LN2 0.69314718055994530942 /* log_e 2 */
  436. # define M_LN10 2.30258509299404568402 /* log_e 10 */
  437. # define M_PI 3.14159265358979323846 /* pi */
  438. # define M_PI_2 1.57079632679489661923 /* pi/2 */
  439. # define M_PI_4 0.78539816339744830962 /* pi/4 */
  440. # define M_1_PI 0.31830988618379067154 /* 1/pi */
  441. # define M_2_PI 0.63661977236758134308 /* 2/pi */
  442. # define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */
  443. # define M_SQRT2 1.41421356237309504880 /* sqrt(2) */
  444. # define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */
  445. #endif
  446. /* The above constants are not adequate for computation using `long double's.
  447. Therefore we provide as an extension constants with similar names as a
  448. GNU extension. Provide enough digits for the 128-bit IEEE quad. */
  449. #ifdef __USE_GNU
  450. # define M_El 2.718281828459045235360287471352662498L /* e */
  451. # define M_LOG2El 1.442695040888963407359924681001892137L /* log_2 e */
  452. # define M_LOG10El 0.434294481903251827651128918916605082L /* log_10 e */
  453. # define M_LN2l 0.693147180559945309417232121458176568L /* log_e 2 */
  454. # define M_LN10l 2.302585092994045684017991454684364208L /* log_e 10 */
  455. # define M_PIl 3.141592653589793238462643383279502884L /* pi */
  456. # define M_PI_2l 1.570796326794896619231321691639751442L /* pi/2 */
  457. # define M_PI_4l 0.785398163397448309615660845819875721L /* pi/4 */
  458. # define M_1_PIl 0.318309886183790671537767526745028724L /* 1/pi */
  459. # define M_2_PIl 0.636619772367581343075535053490057448L /* 2/pi */
  460. # define M_2_SQRTPIl 1.128379167095512573896158903121545172L /* 2/sqrt(pi) */
  461. # define M_SQRT2l 1.414213562373095048801688724209698079L /* sqrt(2) */
  462. # define M_SQRT1_2l 0.707106781186547524400844362104849039L /* 1/sqrt(2) */
  463. #endif
  464. /* When compiling in strict ISO C compatible mode we must not use the
  465. inline functions since they, among other things, do not set the
  466. `errno' variable correctly. */
  467. #if defined __STRICT_ANSI__ && !defined __NO_MATH_INLINES
  468. # define __NO_MATH_INLINES 1
  469. #endif
  470. #if defined __USE_ISOC99 && __GNUC_PREREQ(2,97)
  471. /* ISO C99 defines some macros to compare number while taking care for
  472. unordered numbers. Many FPUs provide special instructions to support
  473. these operations. Generic support in GCC for these as builtins went
  474. in before 3.0.0, but not all cpus added their patterns. We define
  475. versions that use the builtins here, and <bits/mathinline.h> will
  476. undef/redefine as appropriate for the specific GCC version in use. */
  477. # define isgreater(x, y) __builtin_isgreater(x, y)
  478. # define isgreaterequal(x, y) __builtin_isgreaterequal(x, y)
  479. # define isless(x, y) __builtin_isless(x, y)
  480. # define islessequal(x, y) __builtin_islessequal(x, y)
  481. # define islessgreater(x, y) __builtin_islessgreater(x, y)
  482. # define isunordered(u, v) __builtin_isunordered(u, v)
  483. #endif
  484. /* Get machine-dependent inline versions (if there are any). */
  485. #ifdef __USE_EXTERN_INLINES
  486. # include <bits/mathinline.h>
  487. #endif
  488. /* Define special entry points to use when the compiler got told to
  489. only expect finite results. */
  490. #if defined __FINITE_MATH_ONLY__ && __FINITE_MATH_ONLY__ > 0
  491. # include <bits/math-finite.h>
  492. #endif
  493. #ifdef __USE_ISOC99
  494. /* If we've still got undefined comparison macros, provide defaults. */
  495. /* Return nonzero value if X is greater than Y. */
  496. # ifndef isgreater
  497. # define isgreater(x, y) \
  498. (__extension__ \
  499. ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y); \
  500. !isunordered (__x, __y) && __x > __y; }))
  501. # endif
  502. /* Return nonzero value if X is greater than or equal to Y. */
  503. # ifndef isgreaterequal
  504. # define isgreaterequal(x, y) \
  505. (__extension__ \
  506. ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y); \
  507. !isunordered (__x, __y) && __x >= __y; }))
  508. # endif
  509. /* Return nonzero value if X is less than Y. */
  510. # ifndef isless
  511. # define isless(x, y) \
  512. (__extension__ \
  513. ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y); \
  514. !isunordered (__x, __y) && __x < __y; }))
  515. # endif
  516. /* Return nonzero value if X is less than or equal to Y. */
  517. # ifndef islessequal
  518. # define islessequal(x, y) \
  519. (__extension__ \
  520. ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y); \
  521. !isunordered (__x, __y) && __x <= __y; }))
  522. # endif
  523. /* Return nonzero value if either X is less than Y or Y is less than X. */
  524. # ifndef islessgreater
  525. # define islessgreater(x, y) \
  526. (__extension__ \
  527. ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y); \
  528. !isunordered (__x, __y) && (__x < __y || __y < __x); }))
  529. # endif
  530. /* Return nonzero value if arguments are unordered. */
  531. # ifndef isunordered
  532. # define isunordered(u, v) \
  533. (__extension__ \
  534. ({ __typeof__(u) __u = (u); __typeof__(v) __v = (v); \
  535. fpclassify (__u) == FP_NAN || fpclassify (__v) == FP_NAN; }))
  536. # endif
  537. #endif
  538. #if __GLIBC_USE (IEC_60559_BFP_EXT)
  539. /* An expression whose type has the widest of the evaluation formats
  540. of X and Y (which are of floating-point types). */
  541. # if __FLT_EVAL_METHOD__ == 2 || __FLT_EVAL_METHOD__ > 64
  542. # define __MATH_EVAL_FMT2(x, y) ((x) + (y) + 0.0L)
  543. # elif __FLT_EVAL_METHOD__ == 1 || __FLT_EVAL_METHOD__ > 32
  544. # define __MATH_EVAL_FMT2(x, y) ((x) + (y) + 0.0)
  545. # else
  546. # define __MATH_EVAL_FMT2(x, y) ((x) + (y))
  547. # endif
  548. /* Return X == Y but raising "invalid" and setting errno if X or Y is
  549. a NaN. */
  550. # define iseqsig(x, y) \
  551. __MATH_TG (__MATH_EVAL_FMT2 (x, y), __iseqsig, ((x), (y)))
  552. #endif
  553. __END_DECLS
  554. #endif /* math.h */