math.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  1. #ifndef _MATH_H
  2. #define _MATH_H
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. #include <features.h>
  7. #define __NEED_float_t
  8. #define __NEED_double_t
  9. #include <bits/alltypes.h>
  10. #if 100*__GNUC__+__GNUC_MINOR__ >= 303
  11. #define NAN __builtin_nanf("")
  12. #define INFINITY __builtin_inff()
  13. #else
  14. #define NAN (0.0f/0.0f)
  15. #define INFINITY 1e5000f
  16. #endif
  17. #define HUGE_VALF INFINITY
  18. #define HUGE_VAL ((double)INFINITY)
  19. #define HUGE_VALL ((long double)INFINITY)
  20. #define MATH_ERRNO 1
  21. #define MATH_ERREXCEPT 2
  22. #define math_errhandling 2
  23. #define FP_ILOGBNAN (-1-0x7fffffff)
  24. #define FP_ILOGB0 FP_ILOGBNAN
  25. #define FP_NAN 0
  26. #define FP_INFINITE 1
  27. #define FP_ZERO 2
  28. #define FP_SUBNORMAL 3
  29. #define FP_NORMAL 4
  30. #ifdef __FP_FAST_FMA
  31. #define FP_FAST_FMA 1
  32. #endif
  33. #ifdef __FP_FAST_FMAF
  34. #define FP_FAST_FMAF 1
  35. #endif
  36. #ifdef __FP_FAST_FMAL
  37. #define FP_FAST_FMAL 1
  38. #endif
  39. int __fpclassify(double);
  40. int __fpclassifyf(float);
  41. int __fpclassifyl(long double);
  42. static __inline unsigned __FLOAT_BITS(float __f)
  43. {
  44. union {float __f; unsigned __i;} __u;
  45. __u.__f = __f;
  46. return __u.__i;
  47. }
  48. static __inline unsigned long long __DOUBLE_BITS(double __f)
  49. {
  50. union {double __f; unsigned long long __i;} __u;
  51. __u.__f = __f;
  52. return __u.__i;
  53. }
  54. #define fpclassify(x) ( \
  55. sizeof(x) == sizeof(float) ? __fpclassifyf(x) : \
  56. sizeof(x) == sizeof(double) ? __fpclassify(x) : \
  57. __fpclassifyl(x) )
  58. #define isinf(x) ( \
  59. sizeof(x) == sizeof(float) ? (__FLOAT_BITS(x) & 0x7fffffff) == 0x7f800000 : \
  60. sizeof(x) == sizeof(double) ? (__DOUBLE_BITS(x) & -1ULL>>1) == 0x7ffULL<<52 : \
  61. __fpclassifyl(x) == FP_INFINITE)
  62. #define isnan(x) ( \
  63. sizeof(x) == sizeof(float) ? (__FLOAT_BITS(x) & 0x7fffffff) > 0x7f800000 : \
  64. sizeof(x) == sizeof(double) ? (__DOUBLE_BITS(x) & -1ULL>>1) > 0x7ffULL<<52 : \
  65. __fpclassifyl(x) == FP_NAN)
  66. #define isnormal(x) ( \
  67. sizeof(x) == sizeof(float) ? ((__FLOAT_BITS(x)+0x00800000) & 0x7fffffff) >= 0x01000000 : \
  68. sizeof(x) == sizeof(double) ? ((__DOUBLE_BITS(x)+(1ULL<<52)) & -1ULL>>1) >= 1ULL<<53 : \
  69. __fpclassifyl(x) == FP_NORMAL)
  70. #define isfinite(x) ( \
  71. sizeof(x) == sizeof(float) ? (__FLOAT_BITS(x) & 0x7fffffff) < 0x7f800000 : \
  72. sizeof(x) == sizeof(double) ? (__DOUBLE_BITS(x) & -1ULL>>1) < 0x7ffULL<<52 : \
  73. __fpclassifyl(x) > FP_INFINITE)
  74. int __signbit(double);
  75. int __signbitf(float);
  76. int __signbitl(long double);
  77. #define signbit(x) ( \
  78. sizeof(x) == sizeof(float) ? (int)(__FLOAT_BITS(x)>>31) : \
  79. sizeof(x) == sizeof(double) ? (int)(__DOUBLE_BITS(x)>>63) : \
  80. __signbitl(x) )
  81. #define isunordered(x,y) (isnan((x)) ? ((void)(y),1) : isnan((y)))
  82. #define __ISREL_DEF(rel, op, type) \
  83. static __inline int __is##rel(type __x, type __y) \
  84. { return !isunordered(__x,__y) && __x op __y; }
  85. __ISREL_DEF(lessf, <, float_t)
  86. __ISREL_DEF(less, <, double_t)
  87. __ISREL_DEF(lessl, <, long double)
  88. __ISREL_DEF(lessequalf, <=, float_t)
  89. __ISREL_DEF(lessequal, <=, double_t)
  90. __ISREL_DEF(lessequall, <=, long double)
  91. __ISREL_DEF(lessgreaterf, !=, float_t)
  92. __ISREL_DEF(lessgreater, !=, double_t)
  93. __ISREL_DEF(lessgreaterl, !=, long double)
  94. __ISREL_DEF(greaterf, >, float_t)
  95. __ISREL_DEF(greater, >, double_t)
  96. __ISREL_DEF(greaterl, >, long double)
  97. __ISREL_DEF(greaterequalf, >=, float_t)
  98. __ISREL_DEF(greaterequal, >=, double_t)
  99. __ISREL_DEF(greaterequall, >=, long double)
  100. #define __tg_pred_2(x, y, p) ( \
  101. sizeof((x)+(y)) == sizeof(float) ? p##f(x, y) : \
  102. sizeof((x)+(y)) == sizeof(double) ? p(x, y) : \
  103. p##l(x, y) )
  104. #define isless(x, y) __tg_pred_2(x, y, __isless)
  105. #define islessequal(x, y) __tg_pred_2(x, y, __islessequal)
  106. #define islessgreater(x, y) __tg_pred_2(x, y, __islessgreater)
  107. #define isgreater(x, y) __tg_pred_2(x, y, __isgreater)
  108. #define isgreaterequal(x, y) __tg_pred_2(x, y, __isgreaterequal)
  109. double acos(double);
  110. float acosf(float);
  111. long double acosl(long double);
  112. double acosh(double);
  113. float acoshf(float);
  114. long double acoshl(long double);
  115. double asin(double);
  116. float asinf(float);
  117. long double asinl(long double);
  118. double asinh(double);
  119. float asinhf(float);
  120. long double asinhl(long double);
  121. double atan(double);
  122. float atanf(float);
  123. long double atanl(long double);
  124. double atan2(double, double);
  125. float atan2f(float, float);
  126. long double atan2l(long double, long double);
  127. double atanh(double);
  128. float atanhf(float);
  129. long double atanhl(long double);
  130. double cbrt(double);
  131. float cbrtf(float);
  132. long double cbrtl(long double);
  133. double ceil(double);
  134. float ceilf(float);
  135. long double ceill(long double);
  136. double copysign(double, double);
  137. float copysignf(float, float);
  138. long double copysignl(long double, long double);
  139. double cos(double);
  140. float cosf(float);
  141. long double cosl(long double);
  142. double cosh(double);
  143. float coshf(float);
  144. long double coshl(long double);
  145. double erf(double);
  146. float erff(float);
  147. long double erfl(long double);
  148. double erfc(double);
  149. float erfcf(float);
  150. long double erfcl(long double);
  151. double exp(double);
  152. float expf(float);
  153. long double expl(long double);
  154. double exp2(double);
  155. float exp2f(float);
  156. long double exp2l(long double);
  157. double expm1(double);
  158. float expm1f(float);
  159. long double expm1l(long double);
  160. double fabs(double);
  161. float fabsf(float);
  162. long double fabsl(long double);
  163. double fdim(double, double);
  164. float fdimf(float, float);
  165. long double fdiml(long double, long double);
  166. double floor(double);
  167. float floorf(float);
  168. long double floorl(long double);
  169. double fma(double, double, double);
  170. float fmaf(float, float, float);
  171. long double fmal(long double, long double, long double);
  172. double fmax(double, double);
  173. float fmaxf(float, float);
  174. long double fmaxl(long double, long double);
  175. double fmin(double, double);
  176. float fminf(float, float);
  177. long double fminl(long double, long double);
  178. double fmod(double, double);
  179. float fmodf(float, float);
  180. long double fmodl(long double, long double);
  181. double frexp(double, int *);
  182. float frexpf(float, int *);
  183. long double frexpl(long double, int *);
  184. double hypot(double, double);
  185. float hypotf(float, float);
  186. long double hypotl(long double, long double);
  187. int ilogb(double);
  188. int ilogbf(float);
  189. int ilogbl(long double);
  190. double ldexp(double, int);
  191. float ldexpf(float, int);
  192. long double ldexpl(long double, int);
  193. double lgamma(double);
  194. float lgammaf(float);
  195. long double lgammal(long double);
  196. long long llrint(double);
  197. long long llrintf(float);
  198. long long llrintl(long double);
  199. long long llround(double);
  200. long long llroundf(float);
  201. long long llroundl(long double);
  202. double log(double);
  203. float logf(float);
  204. long double logl(long double);
  205. double log10(double);
  206. float log10f(float);
  207. long double log10l(long double);
  208. double log1p(double);
  209. float log1pf(float);
  210. long double log1pl(long double);
  211. double log2(double);
  212. float log2f(float);
  213. long double log2l(long double);
  214. double logb(double);
  215. float logbf(float);
  216. long double logbl(long double);
  217. long lrint(double);
  218. long lrintf(float);
  219. long lrintl(long double);
  220. long lround(double);
  221. long lroundf(float);
  222. long lroundl(long double);
  223. double modf(double, double *);
  224. float modff(float, float *);
  225. long double modfl(long double, long double *);
  226. double nan(const char *);
  227. float nanf(const char *);
  228. long double nanl(const char *);
  229. double nearbyint(double);
  230. float nearbyintf(float);
  231. long double nearbyintl(long double);
  232. double nextafter(double, double);
  233. float nextafterf(float, float);
  234. long double nextafterl(long double, long double);
  235. double nexttoward(double, long double);
  236. float nexttowardf(float, long double);
  237. long double nexttowardl(long double, long double);
  238. double pow(double, double);
  239. float powf(float, float);
  240. long double powl(long double, long double);
  241. double remainder(double, double);
  242. float remainderf(float, float);
  243. long double remainderl(long double, long double);
  244. double remquo(double, double, int *);
  245. float remquof(float, float, int *);
  246. long double remquol(long double, long double, int *);
  247. double rint(double);
  248. float rintf(float);
  249. long double rintl(long double);
  250. double round(double);
  251. float roundf(float);
  252. long double roundl(long double);
  253. double scalbln(double, long);
  254. float scalblnf(float, long);
  255. long double scalblnl(long double, long);
  256. double scalbn(double, int);
  257. float scalbnf(float, int);
  258. long double scalbnl(long double, int);
  259. double sin(double);
  260. float sinf(float);
  261. long double sinl(long double);
  262. double sinh(double);
  263. float sinhf(float);
  264. long double sinhl(long double);
  265. double sqrt(double);
  266. float sqrtf(float);
  267. long double sqrtl(long double);
  268. double tan(double);
  269. float tanf(float);
  270. long double tanl(long double);
  271. double tanh(double);
  272. float tanhf(float);
  273. long double tanhl(long double);
  274. double tgamma(double);
  275. float tgammaf(float);
  276. long double tgammal(long double);
  277. double trunc(double);
  278. float truncf(float);
  279. long double truncl(long double);
  280. #if defined(_XOPEN_SOURCE) || defined(_BSD_SOURCE)
  281. #undef MAXFLOAT
  282. #define MAXFLOAT 3.40282346638528859812e+38F
  283. #endif
  284. #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
  285. #define M_E 2.7182818284590452354 /* e */
  286. #define M_LOG2E 1.4426950408889634074 /* log_2 e */
  287. #define M_LOG10E 0.43429448190325182765 /* log_10 e */
  288. #define M_LN2 0.69314718055994530942 /* log_e 2 */
  289. #define M_LN10 2.30258509299404568402 /* log_e 10 */
  290. #define M_PI 3.14159265358979323846 /* pi */
  291. #define M_PI_2 1.57079632679489661923 /* pi/2 */
  292. #define M_PI_4 0.78539816339744830962 /* pi/4 */
  293. #define M_1_PI 0.31830988618379067154 /* 1/pi */
  294. #define M_2_PI 0.63661977236758134308 /* 2/pi */
  295. #define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */
  296. #define M_SQRT2 1.41421356237309504880 /* sqrt(2) */
  297. #define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */
  298. extern int signgam;
  299. double j0(double);
  300. double j1(double);
  301. double jn(int, double);
  302. double y0(double);
  303. double y1(double);
  304. double yn(int, double);
  305. #endif
  306. #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
  307. #define HUGE 3.40282346638528859812e+38F
  308. double drem(double, double);
  309. float dremf(float, float);
  310. int finite(double);
  311. int finitef(float);
  312. double scalb(double, double);
  313. float scalbf(float, float);
  314. double significand(double);
  315. float significandf(float);
  316. double lgamma_r(double, int*);
  317. float lgammaf_r(float, int*);
  318. float j0f(float);
  319. float j1f(float);
  320. float jnf(int, float);
  321. float y0f(float);
  322. float y1f(float);
  323. float ynf(int, float);
  324. #endif
  325. #ifdef _GNU_SOURCE
  326. long double lgammal_r(long double, int*);
  327. void sincos(double, double*, double*);
  328. void sincosf(float, float*, float*);
  329. void sincosl(long double, long double*, long double*);
  330. double exp10(double);
  331. float exp10f(float);
  332. long double exp10l(long double);
  333. double pow10(double);
  334. float pow10f(float);
  335. long double pow10l(long double);
  336. #endif
  337. #ifdef __cplusplus
  338. }
  339. #endif
  340. #endif