math.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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_E 2.7182818284590452354
  26. #define M_LOG2E 1.4426950408889634074
  27. #define M_LOG10E 0.43429448190325182765
  28. #define M_LN2 0.69314718055994530942
  29. #define M_LN10 2.30258509299404568402
  30. #define M_PI 3.14159265358979323846
  31. #define M_PI_2 1.57079632679489661923
  32. #define M_PI_4 0.78539816339744830962
  33. #define M_1_PI 0.31830988618379067154
  34. #define M_2_PI 0.63661977236758134308
  35. #define M_2_SQRTPI 1.12837916709551257390
  36. #define M_SQRT2 1.41421356237309504880
  37. #define M_SQRT1_2 0.70710678118654752440
  38. #define M_Ef32 2.7182818284590452354f
  39. #define M_LOG2Ef32 1.4426950408889634074f
  40. #define M_LOG10Ef32 0.43429448190325182765f
  41. #define M_LN2f32 0.69314718055994530942f
  42. #define M_LN10f32 2.30258509299404568402f
  43. #define M_PIf32 3.14159265358979323846f
  44. #define M_PI_2f32 1.57079632679489661923f
  45. #define M_PI_4f32 0.78539816339744830962f
  46. #define M_1_PIf32 0.31830988618379067154f
  47. #define M_2_PIf32 0.63661977236758134308f
  48. #define M_2_SQRTPIf32 1.12837916709551257390f
  49. #define M_SQRT2f32 1.41421356237309504880f
  50. #define M_SQRT1_2f32 0.70710678118654752440f
  51. #define FP_NAN 0
  52. #define FP_INFINITE 1
  53. #define FP_ZERO 2
  54. #define FP_SUBNORMAL 3
  55. #define FP_NORMAL 4
  56. #define fpclassify(x) __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_ZERO, FP_SUBNORMAL, FP_ZERO, x)
  57. #define signbit(x) __builtin_signbit(x)
  58. #define isnan(x) __builtin_isnan(x)
  59. #define isinf(x) __builtin_isinf_sign(x)
  60. #define isfinite(x) __builtin_isfinite(x)
  61. #define isnormal(x) __builtin_isnormal(x)
  62. #define isgreater(x, y) __builtin_isgreater((x), (y))
  63. #define isgreaterequal(x, y) __builtin_isgreaterequal((x), (y))
  64. #define isless(x, y) __builtin_isless((x), (y))
  65. #define islessequal(x, y) __builtin_islessequal((x), (y))
  66. #define islessgreater(x, y) __builtin_islessgreater((x), (y))
  67. #define isunordered(x, y) __builtin_isunordered((x), (y))
  68. #define DOUBLE_MAX ((double)0b0111111111101111111111111111111111111111111111111111111111111111)
  69. #define DOUBLE_MIN ((double)0b0000000000010000000000000000000000000000000000000000000000000000)
  70. #define FP_ILOGB0 INT_MIN
  71. #define FP_ILOGNAN INT_MAX
  72. #define FLT_EVAL_METHOD __FLT_EVAL_METHOD__
  73. #if FLT_EVAL_METHOD == 0
  74. typedef float float_t;
  75. typedef double double_t;
  76. #elif FLT_EVAL_METHOD == 1
  77. typedef double float_t;
  78. typedef double double_t;
  79. #elif FLT_EVAL_METHOD == 2
  80. typedef long double float_t;
  81. typedef long double double_t;
  82. #else
  83. typedef float float_t;
  84. typedef double double_t;
  85. #endif
  86. /* Basic floating point operations */
  87. long double fabsl(long double) NOEXCEPT;
  88. double fabs(double) NOEXCEPT;
  89. float fabsf(float) NOEXCEPT;
  90. long double fmodl(long double, long double) NOEXCEPT;
  91. double fmod(double, double) NOEXCEPT;
  92. float fmodf(float, float) NOEXCEPT;
  93. long double fmaxl(long double, long double) NOEXCEPT;
  94. double fmax(double, double) NOEXCEPT;
  95. float fmaxf(float, float) NOEXCEPT;
  96. long double fminl(long double, long double) NOEXCEPT;
  97. double fmin(double, double) NOEXCEPT;
  98. float fminf(float, float) NOEXCEPT;
  99. long double remainderl(long double, long double) NOEXCEPT;
  100. double remainder(double, double) NOEXCEPT;
  101. float remainderf(float, float) NOEXCEPT;
  102. long double nanl(const char*) NOEXCEPT;
  103. double nan(const char*) NOEXCEPT;
  104. float nanf(const char*) NOEXCEPT;
  105. /* Exponential functions */
  106. long double expl(long double) NOEXCEPT;
  107. double exp(double) NOEXCEPT;
  108. float expf(float) NOEXCEPT;
  109. long double exp2l(long double) NOEXCEPT;
  110. double exp2(double) NOEXCEPT;
  111. float exp2f(float) NOEXCEPT;
  112. long double expm1l(long double) NOEXCEPT;
  113. double expm1(double) NOEXCEPT;
  114. float expm1f(float) NOEXCEPT;
  115. long double logl(long double) NOEXCEPT;
  116. double log(double) NOEXCEPT;
  117. float logf(float) NOEXCEPT;
  118. double log2(double) NOEXCEPT;
  119. float log2f(float) NOEXCEPT;
  120. long double log2l(long double) NOEXCEPT;
  121. long double log10l(long double) NOEXCEPT;
  122. double log10(double) NOEXCEPT;
  123. float log10f(float) NOEXCEPT;
  124. long double log1pl(long double) NOEXCEPT;
  125. double log1p(double) NOEXCEPT;
  126. float log1pf(float) NOEXCEPT;
  127. /* Power functions */
  128. long double powl(long double x, long double y) NOEXCEPT;
  129. double pow(double x, double y) NOEXCEPT;
  130. float powf(float x, float y) NOEXCEPT;
  131. long double sqrtl(long double) NOEXCEPT;
  132. double sqrt(double) NOEXCEPT;
  133. float sqrtf(float) NOEXCEPT;
  134. long double cbrtl(long double) NOEXCEPT;
  135. double cbrt(double) NOEXCEPT;
  136. float cbrtf(float) NOEXCEPT;
  137. long double hypotl(long double, long double) NOEXCEPT;
  138. double hypot(double, double) NOEXCEPT;
  139. float hypotf(float, float) NOEXCEPT;
  140. /* Trigonometric functions */
  141. long double sinl(long double) NOEXCEPT;
  142. double sin(double) NOEXCEPT;
  143. float sinf(float) NOEXCEPT;
  144. long double cosl(long double) NOEXCEPT;
  145. double cos(double) NOEXCEPT;
  146. float cosf(float) NOEXCEPT;
  147. long double tanl(long double) NOEXCEPT;
  148. double tan(double) NOEXCEPT;
  149. float tanf(float) NOEXCEPT;
  150. long double asinl(long double) NOEXCEPT;
  151. double asin(double) NOEXCEPT;
  152. float asinf(float) NOEXCEPT;
  153. long double acosl(long double) NOEXCEPT;
  154. double acos(double) NOEXCEPT;
  155. float acosf(float) NOEXCEPT;
  156. long double atanl(long double) NOEXCEPT;
  157. double atan(double) NOEXCEPT;
  158. float atanf(float) NOEXCEPT;
  159. long double atan2l(long double, long double) NOEXCEPT;
  160. double atan2(double, double) NOEXCEPT;
  161. float atan2f(float, float) NOEXCEPT;
  162. /* Hyperbolic functions*/
  163. long double sinhl(long double) NOEXCEPT;
  164. double sinh(double) NOEXCEPT;
  165. float sinhf(float) NOEXCEPT;
  166. long double coshl(long double) NOEXCEPT;
  167. double cosh(double) NOEXCEPT;
  168. float coshf(float) NOEXCEPT;
  169. long double tanhl(long double) NOEXCEPT;
  170. double tanh(double) NOEXCEPT;
  171. float tanhf(float) NOEXCEPT;
  172. long double asinhl(long double) NOEXCEPT;
  173. double asinh(double) NOEXCEPT;
  174. float asinhf(float) NOEXCEPT;
  175. long double acoshl(long double) NOEXCEPT;
  176. double acosh(double) NOEXCEPT;
  177. float acoshf(float) NOEXCEPT;
  178. long double atanhl(long double) NOEXCEPT;
  179. double atanh(double) NOEXCEPT;
  180. float atanhf(float) NOEXCEPT;
  181. /* Error and gamma functions */
  182. long double erfl(long double) NOEXCEPT;
  183. double erf(double) NOEXCEPT;
  184. float erff(float) NOEXCEPT;
  185. long double erfcl(long double) NOEXCEPT;
  186. double erfc(double) NOEXCEPT;
  187. float erfcf(float) NOEXCEPT;
  188. double gamma(double) NOEXCEPT;
  189. long double tgammal(long double) NOEXCEPT;
  190. double tgamma(double) NOEXCEPT;
  191. float tgammaf(float) NOEXCEPT;
  192. long double lgammal(long double) NOEXCEPT;
  193. double lgamma(double) NOEXCEPT;
  194. float lgammaf(float) NOEXCEPT;
  195. long double lgammal_r(long double, int*) NOEXCEPT;
  196. double lgamma_r(double, int*) NOEXCEPT;
  197. float lgammaf_r(float, int*) NOEXCEPT;
  198. extern int signgam;
  199. /* Nearest integer floating point operations */
  200. long double ceill(long double) NOEXCEPT;
  201. double ceil(double) NOEXCEPT;
  202. float ceilf(float) NOEXCEPT;
  203. long double floorl(long double) NOEXCEPT;
  204. double floor(double) NOEXCEPT;
  205. float floorf(float) NOEXCEPT;
  206. long double truncl(long double) NOEXCEPT;
  207. double trunc(double) NOEXCEPT;
  208. float truncf(float) NOEXCEPT;
  209. float roundf(float) NOEXCEPT;
  210. double round(double) NOEXCEPT;
  211. long double roundl(long double) NOEXCEPT;
  212. long lroundf(float) NOEXCEPT;
  213. long lround(double) NOEXCEPT;
  214. long lroundl(long double) NOEXCEPT;
  215. long long llroundf(float) NOEXCEPT;
  216. long long llround(double) NOEXCEPT;
  217. long long llroundd(long double) NOEXCEPT;
  218. float rintf(float) NOEXCEPT;
  219. double rint(double) NOEXCEPT;
  220. long double rintl(long double) NOEXCEPT;
  221. long lrintl(long double) NOEXCEPT;
  222. long lrint(double) NOEXCEPT;
  223. long lrintf(float) NOEXCEPT;
  224. long long llrintl(long double) NOEXCEPT;
  225. long long llrint(double) NOEXCEPT;
  226. long long llrintf(float) NOEXCEPT;
  227. /* Floating point manipulation functions */
  228. long double frexpl(long double, int* exp) NOEXCEPT;
  229. double frexp(double, int* exp) NOEXCEPT;
  230. float frexpf(float, int* exp) NOEXCEPT;
  231. long double ldexpl(long double, int exp) NOEXCEPT;
  232. double ldexp(double, int exp) NOEXCEPT;
  233. float ldexpf(float, int exp) NOEXCEPT;
  234. long double modfl(long double, long double*) NOEXCEPT;
  235. double modf(double, double*) NOEXCEPT;
  236. float modff(float, float*) NOEXCEPT;
  237. float scalbnf(float, int) NOEXCEPT;
  238. double scalbn(double, int) NOEXCEPT;
  239. long double scalbnl(long double, int) NOEXCEPT;
  240. float scalbnlf(float, long) NOEXCEPT;
  241. double scalbln(double, long) NOEXCEPT;
  242. long double scalblnl(long double, long) NOEXCEPT;
  243. int ilogbl(long double) NOEXCEPT;
  244. int ilogb(double) NOEXCEPT;
  245. int ilogbf(float) NOEXCEPT;
  246. long double logbl(long double) NOEXCEPT;
  247. double logb(double) NOEXCEPT;
  248. float logbf(float) NOEXCEPT;
  249. double nextafter(double, double) NOEXCEPT;
  250. float nextafterf(float, float) NOEXCEPT;
  251. long double nextafterl(long double, long double) NOEXCEPT;
  252. double nexttoward(double, long double) NOEXCEPT;
  253. float nexttowardf(float, long double) NOEXCEPT;
  254. long double nexttowardl(long double, long double) NOEXCEPT;
  255. float copysignf(float x, float y) NOEXCEPT;
  256. double copysign(double x, double y) NOEXCEPT;
  257. long double copysignl(long double x, long double y) NOEXCEPT;
  258. __END_DECLS