math.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <float.h>
  8. #include <limits.h>
  9. #include <sys/cdefs.h>
  10. #if __cplusplus >= 201103L
  11. # define NOEXCEPT noexcept
  12. #else
  13. # define NOEXCEPT
  14. #endif
  15. __BEGIN_DECLS
  16. #define MATH_ERRNO 1
  17. #define MATH_ERREXCEPT 2
  18. #define math_errhandling MATH_ERREXCEPT
  19. #define HUGE_VALF __builtin_huge_valf()
  20. #define HUGE_VAL __builtin_huge_val()
  21. #define HUGE_VALL __builtin_huge_vall()
  22. #define INFINITY __builtin_huge_valf()
  23. #define NAN __builtin_nan("")
  24. #define MAXFLOAT FLT_MAX
  25. #define M_El 2.718281828459045235360287471352662498L
  26. #define M_LOG2El 1.442695040888963407359924681001892137L
  27. #define M_LOG10El 0.434294481903251827651128918916605082L
  28. #define M_LN2l 0.693147180559945309417232121458176568L
  29. #define M_LN10l 2.302585092994045684017991454684364208L
  30. #define M_PIl 3.141592653589793238462643383279502884L
  31. #define M_PI_2l 1.570796326794896619231321691639751442L
  32. #define M_PI_4l 0.785398163397448309615660845819875721L
  33. #define M_1_PIl 0.318309886183790671537767526745028724L
  34. #define M_2_PIl 0.636619772367581343075535053490057448L
  35. #define M_2_SQRTPIl 1.128379167095512573896158903121545172L
  36. #define M_SQRT2l 1.414213562373095048801688724209698079L
  37. #define M_SQRT1_2l 0.707106781186547524400844362104849039L
  38. #define M_E 2.7182818284590452354
  39. #define M_LOG2E 1.4426950408889634074
  40. #define M_LOG10E 0.43429448190325182765
  41. #define M_LN2 0.69314718055994530942
  42. #define M_LN10 2.30258509299404568402
  43. #define M_PI 3.14159265358979323846
  44. #define M_PI_2 1.57079632679489661923
  45. #define M_PI_4 0.78539816339744830962
  46. #define M_1_PI 0.31830988618379067154
  47. #define M_2_PI 0.63661977236758134308
  48. #define M_2_SQRTPI 1.12837916709551257390
  49. #define M_SQRT2 1.41421356237309504880
  50. #define M_SQRT1_2 0.70710678118654752440
  51. #define M_Ef32 2.7182818284590452354f
  52. #define M_LOG2Ef32 1.4426950408889634074f
  53. #define M_LOG10Ef32 0.43429448190325182765f
  54. #define M_LN2f32 0.69314718055994530942f
  55. #define M_LN10f32 2.30258509299404568402f
  56. #define M_PIf32 3.14159265358979323846f
  57. #define M_PI_2f32 1.57079632679489661923f
  58. #define M_PI_4f32 0.78539816339744830962f
  59. #define M_1_PIf32 0.31830988618379067154f
  60. #define M_2_PIf32 0.63661977236758134308f
  61. #define M_2_SQRTPIf32 1.12837916709551257390f
  62. #define M_SQRT2f32 1.41421356237309504880f
  63. #define M_SQRT1_2f32 0.70710678118654752440f
  64. #define FP_NAN 0
  65. #define FP_INFINITE 1
  66. #define FP_ZERO 2
  67. #define FP_SUBNORMAL 3
  68. #define FP_NORMAL 4
  69. #define fpclassify(x) __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_ZERO, FP_SUBNORMAL, FP_ZERO, x)
  70. #define signbit(x) __builtin_signbit(x)
  71. #define isnan(x) __builtin_isnan(x)
  72. #define isinf(x) __builtin_isinf_sign(x)
  73. #define isfinite(x) __builtin_isfinite(x)
  74. #define isnormal(x) __builtin_isnormal(x)
  75. #define isgreater(x, y) __builtin_isgreater((x), (y))
  76. #define isgreaterequal(x, y) __builtin_isgreaterequal((x), (y))
  77. #define isless(x, y) __builtin_isless((x), (y))
  78. #define islessequal(x, y) __builtin_islessequal((x), (y))
  79. #define islessgreater(x, y) __builtin_islessgreater((x), (y))
  80. #define isunordered(x, y) __builtin_isunordered((x), (y))
  81. #define DOUBLE_MAX ((double)0b0111111111101111111111111111111111111111111111111111111111111111)
  82. #define DOUBLE_MIN ((double)0b0000000000010000000000000000000000000000000000000000000000000000)
  83. #define FP_ILOGB0 INT_MIN
  84. #define FP_ILOGNAN INT_MAX
  85. #define FLT_EVAL_METHOD __FLT_EVAL_METHOD__
  86. #if FLT_EVAL_METHOD == 0
  87. typedef float float_t;
  88. typedef double double_t;
  89. #elif FLT_EVAL_METHOD == 1
  90. typedef double float_t;
  91. typedef double double_t;
  92. #elif FLT_EVAL_METHOD == 2
  93. typedef long double float_t;
  94. typedef long double double_t;
  95. #else
  96. typedef float float_t;
  97. typedef double double_t;
  98. #endif
  99. /* Basic floating point operations */
  100. long double fabsl(long double) NOEXCEPT;
  101. double fabs(double) NOEXCEPT;
  102. float fabsf(float) NOEXCEPT;
  103. long double fmodl(long double, long double) NOEXCEPT;
  104. double fmod(double, double) NOEXCEPT;
  105. float fmodf(float, float) NOEXCEPT;
  106. long double fmaxl(long double, long double) NOEXCEPT;
  107. double fmax(double, double) NOEXCEPT;
  108. float fmaxf(float, float) NOEXCEPT;
  109. long double fminl(long double, long double) NOEXCEPT;
  110. double fmin(double, double) NOEXCEPT;
  111. float fminf(float, float) NOEXCEPT;
  112. long double remainderl(long double, long double) NOEXCEPT;
  113. double remainder(double, double) NOEXCEPT;
  114. float remainderf(float, float) NOEXCEPT;
  115. long double nanl(char const*) NOEXCEPT;
  116. double nan(char const*) NOEXCEPT;
  117. float nanf(char const*) NOEXCEPT;
  118. /* Exponential functions */
  119. long double expl(long double) NOEXCEPT;
  120. double exp(double) NOEXCEPT;
  121. float expf(float) NOEXCEPT;
  122. long double exp2l(long double) NOEXCEPT;
  123. double exp2(double) NOEXCEPT;
  124. float exp2f(float) NOEXCEPT;
  125. long double expm1l(long double) NOEXCEPT;
  126. double expm1(double) NOEXCEPT;
  127. float expm1f(float) NOEXCEPT;
  128. long double logl(long double) NOEXCEPT;
  129. double log(double) NOEXCEPT;
  130. float logf(float) NOEXCEPT;
  131. double log2(double) NOEXCEPT;
  132. float log2f(float) NOEXCEPT;
  133. long double log2l(long double) NOEXCEPT;
  134. long double log10l(long double) NOEXCEPT;
  135. double log10(double) NOEXCEPT;
  136. float log10f(float) NOEXCEPT;
  137. long double log1pl(long double) NOEXCEPT;
  138. double log1p(double) NOEXCEPT;
  139. float log1pf(float) NOEXCEPT;
  140. /* Power functions */
  141. long double powl(long double x, long double y) NOEXCEPT;
  142. double pow(double x, double y) NOEXCEPT;
  143. float powf(float x, float y) NOEXCEPT;
  144. long double sqrtl(long double) NOEXCEPT;
  145. double sqrt(double) NOEXCEPT;
  146. float sqrtf(float) NOEXCEPT;
  147. long double cbrtl(long double) NOEXCEPT;
  148. double cbrt(double) NOEXCEPT;
  149. float cbrtf(float) NOEXCEPT;
  150. long double hypotl(long double, long double) NOEXCEPT;
  151. double hypot(double, double) NOEXCEPT;
  152. float hypotf(float, float) NOEXCEPT;
  153. /* Trigonometric functions */
  154. long double sinl(long double) NOEXCEPT;
  155. double sin(double) NOEXCEPT;
  156. float sinf(float) NOEXCEPT;
  157. long double cosl(long double) NOEXCEPT;
  158. double cos(double) NOEXCEPT;
  159. float cosf(float) NOEXCEPT;
  160. long double tanl(long double) NOEXCEPT;
  161. double tan(double) NOEXCEPT;
  162. float tanf(float) NOEXCEPT;
  163. long double asinl(long double) NOEXCEPT;
  164. double asin(double) NOEXCEPT;
  165. float asinf(float) NOEXCEPT;
  166. long double acosl(long double) NOEXCEPT;
  167. double acos(double) NOEXCEPT;
  168. float acosf(float) NOEXCEPT;
  169. long double atanl(long double) NOEXCEPT;
  170. double atan(double) NOEXCEPT;
  171. float atanf(float) NOEXCEPT;
  172. long double atan2l(long double, long double) NOEXCEPT;
  173. double atan2(double, double) NOEXCEPT;
  174. float atan2f(float, float) NOEXCEPT;
  175. /* Hyperbolic functions*/
  176. long double sinhl(long double) NOEXCEPT;
  177. double sinh(double) NOEXCEPT;
  178. float sinhf(float) NOEXCEPT;
  179. long double coshl(long double) NOEXCEPT;
  180. double cosh(double) NOEXCEPT;
  181. float coshf(float) NOEXCEPT;
  182. long double tanhl(long double) NOEXCEPT;
  183. double tanh(double) NOEXCEPT;
  184. float tanhf(float) NOEXCEPT;
  185. long double asinhl(long double) NOEXCEPT;
  186. double asinh(double) NOEXCEPT;
  187. float asinhf(float) NOEXCEPT;
  188. long double acoshl(long double) NOEXCEPT;
  189. double acosh(double) NOEXCEPT;
  190. float acoshf(float) NOEXCEPT;
  191. long double atanhl(long double) NOEXCEPT;
  192. double atanh(double) NOEXCEPT;
  193. float atanhf(float) NOEXCEPT;
  194. /* Error and gamma functions */
  195. long double erfl(long double) NOEXCEPT;
  196. double erf(double) NOEXCEPT;
  197. float erff(float) NOEXCEPT;
  198. long double erfcl(long double) NOEXCEPT;
  199. double erfc(double) NOEXCEPT;
  200. float erfcf(float) NOEXCEPT;
  201. double gamma(double) NOEXCEPT;
  202. long double tgammal(long double) NOEXCEPT;
  203. double tgamma(double) NOEXCEPT;
  204. float tgammaf(float) NOEXCEPT;
  205. long double lgammal(long double) NOEXCEPT;
  206. double lgamma(double) NOEXCEPT;
  207. float lgammaf(float) NOEXCEPT;
  208. long double lgammal_r(long double, int*) NOEXCEPT;
  209. double lgamma_r(double, int*) NOEXCEPT;
  210. float lgammaf_r(float, int*) NOEXCEPT;
  211. extern int signgam;
  212. /* Nearest integer floating point operations */
  213. long double ceill(long double) NOEXCEPT;
  214. double ceil(double) NOEXCEPT;
  215. float ceilf(float) NOEXCEPT;
  216. long double floorl(long double) NOEXCEPT;
  217. double floor(double) NOEXCEPT;
  218. float floorf(float) NOEXCEPT;
  219. long double truncl(long double) NOEXCEPT;
  220. double trunc(double) NOEXCEPT;
  221. float truncf(float) NOEXCEPT;
  222. float roundf(float) NOEXCEPT;
  223. double round(double) NOEXCEPT;
  224. long double roundl(long double) NOEXCEPT;
  225. long lroundf(float) NOEXCEPT;
  226. long lround(double) NOEXCEPT;
  227. long lroundl(long double) NOEXCEPT;
  228. long long llroundf(float) NOEXCEPT;
  229. long long llround(double) NOEXCEPT;
  230. long long llroundd(long double) NOEXCEPT;
  231. long long llroundl(long double x) NOEXCEPT;
  232. double nearbyint(double x) NOEXCEPT;
  233. float nearbyintf(float x) NOEXCEPT;
  234. long double nearbyintl(long double x) NOEXCEPT;
  235. float rintf(float) NOEXCEPT;
  236. double rint(double) NOEXCEPT;
  237. long double rintl(long double) NOEXCEPT;
  238. long lrintl(long double) NOEXCEPT;
  239. long lrint(double) NOEXCEPT;
  240. long lrintf(float) NOEXCEPT;
  241. long long llrintl(long double) NOEXCEPT;
  242. long long llrint(double) NOEXCEPT;
  243. long long llrintf(float) NOEXCEPT;
  244. /* Floating point manipulation functions */
  245. long double frexpl(long double, int* exp) NOEXCEPT;
  246. double frexp(double, int* exp) NOEXCEPT;
  247. float frexpf(float, int* exp) NOEXCEPT;
  248. long double ldexpl(long double, int exp) NOEXCEPT;
  249. double ldexp(double, int exp) NOEXCEPT;
  250. float ldexpf(float, int exp) NOEXCEPT;
  251. long double modfl(long double, long double*) NOEXCEPT;
  252. double modf(double, double*) NOEXCEPT;
  253. float modff(float, float*) NOEXCEPT;
  254. float scalbnf(float, int) NOEXCEPT;
  255. double scalbn(double, int) NOEXCEPT;
  256. long double scalbnl(long double, int) NOEXCEPT;
  257. float scalbnlf(float, long) NOEXCEPT;
  258. double scalbln(double, long) NOEXCEPT;
  259. float scalblnf(float, long) NOEXCEPT;
  260. long double scalblnl(long double, long) NOEXCEPT;
  261. int ilogbl(long double) NOEXCEPT;
  262. int ilogb(double) NOEXCEPT;
  263. int ilogbf(float) NOEXCEPT;
  264. long double logbl(long double) NOEXCEPT;
  265. double logb(double) NOEXCEPT;
  266. float logbf(float) NOEXCEPT;
  267. double nextafter(double, double) NOEXCEPT;
  268. float nextafterf(float, float) NOEXCEPT;
  269. long double nextafterl(long double, long double) NOEXCEPT;
  270. double nexttoward(double, long double) NOEXCEPT;
  271. float nexttowardf(float, long double) NOEXCEPT;
  272. long double nexttowardl(long double, long double) NOEXCEPT;
  273. float copysignf(float x, float y) NOEXCEPT;
  274. double copysign(double x, double y) NOEXCEPT;
  275. long double copysignl(long double x, long double y) NOEXCEPT;
  276. /* positive difference */
  277. double fdim(double x, double y) NOEXCEPT;
  278. float fdimf(float x, float y) NOEXCEPT;
  279. long double fdiml(long double x, long double y) NOEXCEPT;
  280. /* floating-point multiply and add */
  281. double fma(double x, double y, double z) NOEXCEPT;
  282. float fmaf(float x, float y, float z) NOEXCEPT;
  283. long double fmal(long double x, long double y, long double z) NOEXCEPT;
  284. /* remainder and part of quotient */
  285. double remquo(double x, double y, int* quo) NOEXCEPT;
  286. float remquof(float x, float y, int* quo) NOEXCEPT;
  287. long double remquol(long double x, long double y, int* quo) NOEXCEPT;
  288. __END_DECLS