math.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice, this
  9. * list of conditions and the following disclaimer.
  10. *
  11. * 2. Redistributions in binary form must reproduce the above copyright notice,
  12. * this list of conditions and the following disclaimer in the documentation
  13. * and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  16. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  19. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  20. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  21. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  22. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  23. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  24. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #pragma once
  27. #include <float.h>
  28. #include <limits.h>
  29. #include <sys/cdefs.h>
  30. #if __cplusplus >= 201103L
  31. # define NOEXCEPT noexcept
  32. #else
  33. # define NOEXCEPT
  34. #endif
  35. __BEGIN_DECLS
  36. #define MATH_ERRNO 1
  37. #define MATH_ERREXCEPT 2
  38. #define math_errhandling MATH_ERREXCEPT
  39. #define HUGE_VALF __builtin_huge_valf()
  40. #define HUGE_VAL __builtin_huge_val()
  41. #define HUGE_VALL __builtin_huge_vall()
  42. #define INFINITY __builtin_huge_val()
  43. #define NAN __builtin_nan("")
  44. #define MAXFLOAT FLT_MAX
  45. #define M_E 2.718281828459045
  46. #define M_PI 3.141592653589793
  47. #define M_PI_2 1.570796326794896
  48. #define M_TAU 6.283185307179586
  49. #define M_DEG2RAD 0.017453292519943
  50. #define M_RAD2DEG 57.29577951308232
  51. #define M_LN2 0.69314718055995
  52. #define M_LN10 2.30258509299405
  53. #define M_SQRT2 1.4142135623730951
  54. #define M_SQRT1_2 0.7071067811865475
  55. #define FP_NAN 0
  56. #define FP_INFINITE 1
  57. #define FP_ZERO 2
  58. #define FP_SUBNORMAL 3
  59. #define FP_NORMAL 4
  60. #define fpclassify(x) __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_ZERO, FP_SUBNORMAL, FP_ZERO, x)
  61. #define signbit(x) __builtin_signbit(x)
  62. #define isnan(x) __builtin_isnan(x)
  63. #define isinf(x) __builtin_isinf_sign(x)
  64. #define isfinite(x) __builtin_isfinite(x)
  65. #define isnormal(x) __builtin_isnormal(x)
  66. #define isgreater(x, y) __builtin_isgreater((x), (y))
  67. #define isgreaterequal(x, y) __builtin_isgreaterequal((x), (y))
  68. #define isless(x, y) __builtin_isless((x), (y))
  69. #define islessequal(x, y) __builtin_islessequal((x), (y))
  70. #define islessgreater(x, y) __builtin_islessgreater((x), (y))
  71. #define isunordered(x, y) __builtin_isunoredered((x), (y))
  72. #define DOUBLE_MAX ((double)0b0111111111101111111111111111111111111111111111111111111111111111)
  73. #define DOUBLE_MIN ((double)0b0000000000010000000000000000000000000000000000000000000000000000)
  74. #define FP_ILOGB0 INT_MIN
  75. #define FP_ILOGNAN INT_MAX
  76. #define FLT_EVAL_METHOD __FLT_EVAL_METHOD__
  77. #if FLT_EVAL_METHOD == 0
  78. typedef float float_t;
  79. typedef double double_t;
  80. #elif FLT_EVAL_METHOD == 1
  81. typedef double float_t;
  82. typedef double double_t;
  83. #elif FLT_EVAL_METHOD == 2
  84. typedef long double float_t;
  85. typedef long double double_t;
  86. #else
  87. typedef float float_t;
  88. typedef double double_t;
  89. #endif
  90. /* Basic floating point operations */
  91. long double fabsl(long double) NOEXCEPT;
  92. double fabs(double) NOEXCEPT;
  93. float fabsf(float) NOEXCEPT;
  94. long double fmodl(long double, long double) NOEXCEPT;
  95. double fmod(double, double) NOEXCEPT;
  96. float fmodf(float, float) NOEXCEPT;
  97. long double fmaxl(long double, long double) NOEXCEPT;
  98. double fmax(double, double) NOEXCEPT;
  99. float fmaxf(float, float) NOEXCEPT;
  100. long double fminl(long double, long double) NOEXCEPT;
  101. double fmin(double, double) NOEXCEPT;
  102. float fminf(float, float) NOEXCEPT;
  103. long double remainderl(long double, long double) NOEXCEPT;
  104. double remainder(double, double) NOEXCEPT;
  105. float remainderf(float, float) NOEXCEPT;
  106. long double nanl(const char*) NOEXCEPT;
  107. double nan(const char*) NOEXCEPT;
  108. float nanf(const char*) NOEXCEPT;
  109. /* Exponential functions */
  110. long double expl(long double) NOEXCEPT;
  111. double exp(double) NOEXCEPT;
  112. float expf(float) NOEXCEPT;
  113. long double exp2l(long double) NOEXCEPT;
  114. double exp2(double) NOEXCEPT;
  115. float exp2f(float) NOEXCEPT;
  116. long double expm1l(long double) NOEXCEPT;
  117. double expm1(double) NOEXCEPT;
  118. float expm1f(float) NOEXCEPT;
  119. long double logl(long double) NOEXCEPT;
  120. double log(double) NOEXCEPT;
  121. float logf(float) NOEXCEPT;
  122. double log2(double) NOEXCEPT;
  123. float log2f(float) NOEXCEPT;
  124. long double log2l(long double) NOEXCEPT;
  125. long double log10l(long double) NOEXCEPT;
  126. double log10(double) NOEXCEPT;
  127. float log10f(float) NOEXCEPT;
  128. long double log1pl(long double) NOEXCEPT;
  129. double log1p(double) NOEXCEPT;
  130. float log1pf(float) NOEXCEPT;
  131. /* Power functions */
  132. long double powl(long double x, long double y) NOEXCEPT;
  133. double pow(double x, double y) NOEXCEPT;
  134. float powf(float x, float y) NOEXCEPT;
  135. long double sqrtl(long double) NOEXCEPT;
  136. double sqrt(double) NOEXCEPT;
  137. float sqrtf(float) NOEXCEPT;
  138. long double cbrtl(long double) NOEXCEPT;
  139. double cbrt(double) NOEXCEPT;
  140. float cbrtf(float) NOEXCEPT;
  141. long double hypotl(long double, long double) NOEXCEPT;
  142. double hypot(double, double) NOEXCEPT;
  143. float hypotf(float, float) NOEXCEPT;
  144. /* Trigonometric functions */
  145. long double sinl(long double) NOEXCEPT;
  146. double sin(double) NOEXCEPT;
  147. float sinf(float) NOEXCEPT;
  148. long double cosl(long double) NOEXCEPT;
  149. double cos(double) NOEXCEPT;
  150. float cosf(float) NOEXCEPT;
  151. long double tanl(long double) NOEXCEPT;
  152. double tan(double) NOEXCEPT;
  153. float tanf(float) NOEXCEPT;
  154. long double asinl(long double) NOEXCEPT;
  155. double asin(double) NOEXCEPT;
  156. float asinf(float) NOEXCEPT;
  157. long double acosl(long double) NOEXCEPT;
  158. double acos(double) NOEXCEPT;
  159. float acosf(float) NOEXCEPT;
  160. long double atanl(long double) NOEXCEPT;
  161. double atan(double) NOEXCEPT;
  162. float atanf(float) NOEXCEPT;
  163. long double atan2l(long double, long double) NOEXCEPT;
  164. double atan2(double, double) NOEXCEPT;
  165. float atan2f(float, float) NOEXCEPT;
  166. /* Hyperbolic functions*/
  167. long double sinhl(long double) NOEXCEPT;
  168. double sinh(double) NOEXCEPT;
  169. float sinhf(float) NOEXCEPT;
  170. long double coshl(long double) NOEXCEPT;
  171. double cosh(double) NOEXCEPT;
  172. float coshf(float) NOEXCEPT;
  173. long double tanhl(long double) NOEXCEPT;
  174. double tanh(double) NOEXCEPT;
  175. float tanhf(float) NOEXCEPT;
  176. long double asinhl(long double) NOEXCEPT;
  177. double asinh(double) NOEXCEPT;
  178. float asinhf(float) NOEXCEPT;
  179. long double acoshl(long double) NOEXCEPT;
  180. double acosh(double) NOEXCEPT;
  181. float acoshf(float) NOEXCEPT;
  182. long double atanhl(long double) NOEXCEPT;
  183. double atanh(double) NOEXCEPT;
  184. float atanhf(float) NOEXCEPT;
  185. /* Error and gamma functions */
  186. long double erfl(long double) NOEXCEPT;
  187. double erf(double) NOEXCEPT;
  188. float erff(float) NOEXCEPT;
  189. long double erfcl(long double) NOEXCEPT;
  190. double erfc(double) NOEXCEPT;
  191. float erfcf(float) NOEXCEPT;
  192. double gamma(double) NOEXCEPT;
  193. long double tgammal(long double) NOEXCEPT;
  194. double tgamma(double) NOEXCEPT;
  195. float tgammaf(float) NOEXCEPT;
  196. long double lgammal(long double) NOEXCEPT;
  197. double lgamma(double) NOEXCEPT;
  198. float lgammaf(float) NOEXCEPT;
  199. long double lgammal_r(long double, int*) NOEXCEPT;
  200. double lgamma_r(double, int*) NOEXCEPT;
  201. float lgammaf_r(float, int*) NOEXCEPT;
  202. extern int signgam;
  203. /* Nearest integer floating point operations */
  204. long double ceill(long double) NOEXCEPT;
  205. double ceil(double) NOEXCEPT;
  206. float ceilf(float) NOEXCEPT;
  207. long double floorl(long double) NOEXCEPT;
  208. double floor(double) NOEXCEPT;
  209. float floorf(float) NOEXCEPT;
  210. long double truncl(long double) NOEXCEPT;
  211. double trunc(double) NOEXCEPT;
  212. float truncf(float) NOEXCEPT;
  213. float roundf(float) NOEXCEPT;
  214. double round(double) NOEXCEPT;
  215. long double roundl(long double) NOEXCEPT;
  216. long lroundf(float) NOEXCEPT;
  217. long lround(double) NOEXCEPT;
  218. long lroundl(long double) NOEXCEPT;
  219. long long llroundf(float) NOEXCEPT;
  220. long long llround(double) NOEXCEPT;
  221. long long llroundd(long double) NOEXCEPT;
  222. float rintf(float) NOEXCEPT;
  223. double rint(double) NOEXCEPT;
  224. long double rintl(long double) NOEXCEPT;
  225. long lrintl(long double) NOEXCEPT;
  226. long lrint(double) NOEXCEPT;
  227. long lrintf(float) NOEXCEPT;
  228. long long llrintl(long double) NOEXCEPT;
  229. long long llrint(double) NOEXCEPT;
  230. long long llrintf(float) NOEXCEPT;
  231. /* Floating point manipulation functions */
  232. long double frexpl(long double, int* exp) NOEXCEPT;
  233. double frexp(double, int* exp) NOEXCEPT;
  234. float frexpf(float, int* exp) NOEXCEPT;
  235. long double ldexpl(long double, int exp) NOEXCEPT;
  236. double ldexp(double, int exp) NOEXCEPT;
  237. float ldexpf(float, int exp) NOEXCEPT;
  238. long double modfl(long double, long double*) NOEXCEPT;
  239. double modf(double, double*) NOEXCEPT;
  240. float modff(float, float*) NOEXCEPT;
  241. float scalbnf(float, int) NOEXCEPT;
  242. double scalbn(double, int) NOEXCEPT;
  243. long double scalbnl(long double, int) NOEXCEPT;
  244. float scalbnlf(float, long) NOEXCEPT;
  245. double scalbln(double, long) NOEXCEPT;
  246. long double scalblnl(long double, long) NOEXCEPT;
  247. int ilogbl(long double) NOEXCEPT;
  248. int ilogb(double) NOEXCEPT;
  249. int ilogbf(float) NOEXCEPT;
  250. long double logbl(long double) NOEXCEPT;
  251. double logb(double) NOEXCEPT;
  252. float logbf(float) NOEXCEPT;
  253. double nextafter(double, double) NOEXCEPT;
  254. float nextafterf(float, float) NOEXCEPT;
  255. long double nextafterl(long double, long double) NOEXCEPT;
  256. double nexttoward(double, long double) NOEXCEPT;
  257. float nexttowardf(float, long double) NOEXCEPT;
  258. long double nexttowardl(long double, long double) NOEXCEPT;
  259. float copysignf(float x, float y) NOEXCEPT;
  260. double copysign(double x, double y) NOEXCEPT;
  261. long double copysignl(long double x, long double y) NOEXCEPT;
  262. __END_DECLS