math.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  1. /* $OpenBSD: math.h,v 1.27 2010/12/14 11:16:15 martynas Exp $ */
  2. /*
  3. * ====================================================
  4. * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
  5. *
  6. * Developed at SunPro, a Sun Microsystems, Inc. business.
  7. * Permission to use, copy, modify, and distribute this
  8. * software is freely granted, provided that this notice
  9. * is preserved.
  10. * ====================================================
  11. */
  12. /*
  13. * from: @(#)fdlibm.h 5.1 93/09/24
  14. */
  15. #ifndef _MATH_H_
  16. #define _MATH_H_
  17. #include <sys/_types.h>
  18. #include <sys/cdefs.h>
  19. #include <sys/limits.h>
  20. #include <float.h>
  21. typedef __float_t float_t;
  22. typedef __double_t double_t;
  23. #define FP_NAN 0x00
  24. #define FP_INFINITE 0x01
  25. #define FP_ZERO 0x02
  26. #define FP_SUBNORMAL 0x03
  27. #define FP_NORMAL 0x04
  28. #define FP_ILOGB0 (-INT_MAX - 1)
  29. #define FP_ILOGBNAN (-INT_MAX - 1)
  30. #define fpclassify(x) \
  31. ((sizeof (x) == sizeof (float)) ? \
  32. __fpclassifyf(x) \
  33. : (sizeof (x) == sizeof (double)) ? \
  34. __fpclassify(x) \
  35. : __fpclassifyl(x))
  36. #define isfinite(x) \
  37. ((sizeof (x) == sizeof (float)) ? \
  38. __isfinitef(x) \
  39. : (sizeof (x) == sizeof (double)) ? \
  40. __isfinite(x) \
  41. : __isfinitel(x))
  42. #define isnormal(x) \
  43. ((sizeof (x) == sizeof (float)) ? \
  44. __isnormalf(x) \
  45. : (sizeof (x) == sizeof (double)) ? \
  46. __isnormal(x) \
  47. : __isnormall(x))
  48. #define signbit(x) \
  49. ((sizeof (x) == sizeof (float)) ? \
  50. __signbitf(x) \
  51. : (sizeof (x) == sizeof (double)) ? \
  52. __signbit(x) \
  53. : __signbitl(x))
  54. #define isinf(x) \
  55. ((sizeof (x) == sizeof (float)) ? \
  56. __isinff(x) \
  57. : (sizeof (x) == sizeof (double)) ? \
  58. __isinf(x) \
  59. : __isinfl(x))
  60. #define isnan(x) \
  61. ((sizeof (x) == sizeof (float)) ? \
  62. __isnanf(x) \
  63. : (sizeof (x) == sizeof (double)) ? \
  64. __isnan(x) \
  65. : __isnanl(x))
  66. #define isgreater(x, y) (!isunordered((x), (y)) && (x) > (y))
  67. #define isgreaterequal(x, y) (!isunordered((x), (y)) && (x) >= (y))
  68. #define isless(x, y) (!isunordered((x), (y)) && (x) < (y))
  69. #define islessequal(x, y) (!isunordered((x), (y)) && (x) <= (y))
  70. #define islessgreater(x, y) (!isunordered((x), (y)) && ((x) > (y) || (y) > (x)))
  71. #define isunordered(x, y) (isnan(x) || isnan(y))
  72. __BEGIN_DECLS
  73. extern char __infinity[];
  74. #define HUGE_VAL (*(double *)(void *)__infinity)
  75. #define HUGE_VALF ((float)HUGE_VAL)
  76. #define HUGE_VALL ((long double)HUGE_VAL)
  77. #define INFINITY HUGE_VALF
  78. extern char __nan[];
  79. #define NAN (*(float *)(void *)__nan)
  80. /*
  81. * ANSI/POSIX
  82. */
  83. double _TLIBC_CDECL_ acos(double);
  84. double _TLIBC_CDECL_ asin(double);
  85. double _TLIBC_CDECL_ atan(double);
  86. double _TLIBC_CDECL_ atan2(double, double);
  87. double _TLIBC_CDECL_ cos(double);
  88. double _TLIBC_CDECL_ sin(double);
  89. double _TLIBC_CDECL_ tan(double);
  90. double _TLIBC_CDECL_ cosh(double);
  91. double _TLIBC_CDECL_ sinh(double);
  92. double _TLIBC_CDECL_ tanh(double);
  93. double _TLIBC_CDECL_ exp(double);
  94. double _TLIBC_CDECL_ frexp(double, int *);
  95. double _TLIBC_CDECL_ ldexp(double, int);
  96. double _TLIBC_CDECL_ log(double);
  97. double _TLIBC_CDECL_ log10(double);
  98. double _TLIBC_CDECL_ modf(double, double *);
  99. double _TLIBC_CDECL_ pow(double, double);
  100. double _TLIBC_CDECL_ sqrt(double);
  101. double _TLIBC_CDECL_ ceil(double);
  102. double _TLIBC_CDECL_ fabs(double);
  103. double _TLIBC_CDECL_ floor(double);
  104. double _TLIBC_CDECL_ fmod(double, double);
  105. /*
  106. * C99
  107. */
  108. double _TLIBC_CDECL_ acosh(double);
  109. double _TLIBC_CDECL_ asinh(double);
  110. double _TLIBC_CDECL_ atanh(double);
  111. double _TLIBC_CDECL_ exp2(double);
  112. double _TLIBC_CDECL_ expm1(double);
  113. int _TLIBC_CDECL_ ilogb(double);
  114. double _TLIBC_CDECL_ log1p(double);
  115. double _TLIBC_CDECL_ log2(double);
  116. double _TLIBC_CDECL_ logb(double);
  117. double _TLIBC_CDECL_ scalbn(double, int);
  118. double _TLIBC_CDECL_ scalbln(double, long int);
  119. double _TLIBC_CDECL_ cbrt(double);
  120. double _TLIBC_CDECL_ hypot(double, double);
  121. double _TLIBC_CDECL_ erf(double);
  122. double _TLIBC_CDECL_ erfc(double);
  123. double _TLIBC_CDECL_ lgamma(double);
  124. double _TLIBC_CDECL_ tgamma(double);
  125. double _TLIBC_CDECL_ nearbyint(double);
  126. double _TLIBC_CDECL_ rint(double);
  127. long int _TLIBC_CDECL_ lrint(double);
  128. long long int _TLIBC_CDECL_ llrint(double);
  129. double _TLIBC_CDECL_ round(double);
  130. long int _TLIBC_CDECL_ lround(double);
  131. long long int _TLIBC_CDECL_ llround(double);
  132. double _TLIBC_CDECL_ trunc(double);
  133. double _TLIBC_CDECL_ remainder(double, double);
  134. double _TLIBC_CDECL_ remquo(double, double, int *);
  135. double _TLIBC_CDECL_ copysign(double, double);
  136. double _TLIBC_CDECL_ nan(const char *);
  137. double _TLIBC_CDECL_ nextafter(double, double);
  138. double _TLIBC_CDECL_ fdim(double, double);
  139. double _TLIBC_CDECL_ fmax(double, double);
  140. double _TLIBC_CDECL_ fmin(double, double);
  141. double _TLIBC_CDECL_ fma(double, double, double);
  142. /*
  143. * Float versions of C99 functions
  144. */
  145. float _TLIBC_CDECL_ acosf(float);
  146. float _TLIBC_CDECL_ asinf(float);
  147. float _TLIBC_CDECL_ atanf(float);
  148. float _TLIBC_CDECL_ atan2f(float, float);
  149. float _TLIBC_CDECL_ cosf(float);
  150. float _TLIBC_CDECL_ sinf(float);
  151. float _TLIBC_CDECL_ tanf(float);
  152. float _TLIBC_CDECL_ acoshf(float);
  153. float _TLIBC_CDECL_ asinhf(float);
  154. float _TLIBC_CDECL_ atanhf(float);
  155. float _TLIBC_CDECL_ coshf(float);
  156. float _TLIBC_CDECL_ sinhf(float);
  157. float _TLIBC_CDECL_ tanhf(float);
  158. float _TLIBC_CDECL_ expf(float);
  159. float _TLIBC_CDECL_ exp2f(float);
  160. float _TLIBC_CDECL_ expm1f(float);
  161. float _TLIBC_CDECL_ frexpf(float, int *);
  162. int _TLIBC_CDECL_ ilogbf(float);
  163. float _TLIBC_CDECL_ ldexpf(float, int);
  164. float _TLIBC_CDECL_ logf(float);
  165. float _TLIBC_CDECL_ log10f(float);
  166. float _TLIBC_CDECL_ log1pf(float);
  167. float _TLIBC_CDECL_ log2f(float);
  168. float _TLIBC_CDECL_ logbf(float);
  169. float _TLIBC_CDECL_ modff(float, float *);
  170. float _TLIBC_CDECL_ scalbnf(float, int);
  171. float _TLIBC_CDECL_ scalblnf(float, long int);
  172. float _TLIBC_CDECL_ cbrtf(float);
  173. float _TLIBC_CDECL_ fabsf(float);
  174. float _TLIBC_CDECL_ hypotf(float, float);
  175. float _TLIBC_CDECL_ powf(float, float);
  176. float _TLIBC_CDECL_ sqrtf(float);
  177. float _TLIBC_CDECL_ erff(float);
  178. float _TLIBC_CDECL_ erfcf(float);
  179. float _TLIBC_CDECL_ lgammaf(float);
  180. float _TLIBC_CDECL_ tgammaf(float);
  181. float _TLIBC_CDECL_ ceilf(float);
  182. float _TLIBC_CDECL_ floorf(float);
  183. float _TLIBC_CDECL_ nearbyintf(float);
  184. float _TLIBC_CDECL_ rintf(float);
  185. long int _TLIBC_CDECL_ lrintf(float);
  186. long long int _TLIBC_CDECL_ llrintf(float);
  187. float _TLIBC_CDECL_ roundf(float);
  188. long int _TLIBC_CDECL_ lroundf(float);
  189. long long int _TLIBC_CDECL_ llroundf(float);
  190. float _TLIBC_CDECL_ truncf(float);
  191. float _TLIBC_CDECL_ fmodf(float, float);
  192. float _TLIBC_CDECL_ remainderf(float, float);
  193. float _TLIBC_CDECL_ remquof(float, float, int *);
  194. float _TLIBC_CDECL_ copysignf(float, float);
  195. float _TLIBC_CDECL_ nanf(const char *);
  196. float _TLIBC_CDECL_ nextafterf(float, float);
  197. float _TLIBC_CDECL_ fdimf(float, float);
  198. float _TLIBC_CDECL_ fmaxf(float, float);
  199. float _TLIBC_CDECL_ fminf(float, float);
  200. float _TLIBC_CDECL_ fmaf(float, float, float);
  201. /*
  202. * Long double versions of C99 functions
  203. */
  204. /* Macros defining long double functions to be their double counterparts
  205. * (long double is synonymous with double in this implementation).
  206. */
  207. long double _TLIBC_CDECL_ acosl(long double);
  208. long double _TLIBC_CDECL_ asinl(long double);
  209. long double _TLIBC_CDECL_ atanl(long double);
  210. long double _TLIBC_CDECL_ atan2l(long double, long double);
  211. long double _TLIBC_CDECL_ cosl(long double);
  212. long double _TLIBC_CDECL_ sinl(long double);
  213. long double _TLIBC_CDECL_ tanl(long double);
  214. long double _TLIBC_CDECL_ acoshl(long double);
  215. long double _TLIBC_CDECL_ asinhl(long double);
  216. long double _TLIBC_CDECL_ atanhl(long double);
  217. long double _TLIBC_CDECL_ coshl(long double);
  218. long double _TLIBC_CDECL_ sinhl(long double);
  219. long double _TLIBC_CDECL_ tanhl(long double);
  220. long double _TLIBC_CDECL_ expl(long double);
  221. long double _TLIBC_CDECL_ exp2l(long double);
  222. long double _TLIBC_CDECL_ expm1l(long double);
  223. long double _TLIBC_CDECL_ frexpl(long double, int *);
  224. int _TLIBC_CDECL_ ilogbl(long double);
  225. long double _TLIBC_CDECL_ ldexpl(long double, int);
  226. long double _TLIBC_CDECL_ logl(long double);
  227. long double _TLIBC_CDECL_ log10l(long double);
  228. long double _TLIBC_CDECL_ log1pl(long double);
  229. long double _TLIBC_CDECL_ log2l(long double);
  230. long double _TLIBC_CDECL_ logbl(long double);
  231. long double _TLIBC_CDECL_ modfl(long double, long double *);
  232. long double _TLIBC_CDECL_ scalbnl(long double, int);
  233. long double _TLIBC_CDECL_ scalblnl(long double, long int);
  234. long double _TLIBC_CDECL_ cbrtl(long double);
  235. long double _TLIBC_CDECL_ fabsl(long double);
  236. long double _TLIBC_CDECL_ hypotl(long double, long double);
  237. long double _TLIBC_CDECL_ powl(long double, long double);
  238. long double _TLIBC_CDECL_ sqrtl(long double);
  239. long double _TLIBC_CDECL_ erfl(long double);
  240. long double _TLIBC_CDECL_ erfcl(long double);
  241. long double _TLIBC_CDECL_ lgammal(long double);
  242. long double _TLIBC_CDECL_ tgammal(long double);
  243. long double _TLIBC_CDECL_ ceill(long double);
  244. long double _TLIBC_CDECL_ floorl(long double);
  245. long double _TLIBC_CDECL_ nearbyintl(long double);
  246. long double _TLIBC_CDECL_ rintl(long double);
  247. long int _TLIBC_CDECL_ lrintl(long double);
  248. long long int _TLIBC_CDECL_ llrintl(long double);
  249. long double _TLIBC_CDECL_ roundl(long double);
  250. long int _TLIBC_CDECL_ lroundl(long double);
  251. long long int _TLIBC_CDECL_ llroundl(long double);
  252. long double _TLIBC_CDECL_ truncl(long double);
  253. long double _TLIBC_CDECL_ fmodl(long double, long double);
  254. long double _TLIBC_CDECL_ remainderl(long double, long double);
  255. long double _TLIBC_CDECL_ remquol(long double, long double, int *);
  256. long double _TLIBC_CDECL_ copysignl(long double, long double);
  257. long double _TLIBC_CDECL_ nanl(const char *);
  258. long double _TLIBC_CDECL_ nextafterl(long double, long double);
  259. long double _TLIBC_CDECL_ fdiml(long double, long double);
  260. long double _TLIBC_CDECL_ fmaxl(long double, long double);
  261. long double _TLIBC_CDECL_ fminl(long double, long double);
  262. long double _TLIBC_CDECL_ fmal(long double, long double, long double);
  263. /* nexttoward():
  264. * The implementation in Intel math library is incompatible with MSVC.
  265. * Because sizeof(long double) is 8bytes with MSVC,
  266. * but the expected long double size is 10bytes.
  267. * And by default, MSVC doesn't provide nexttoward().
  268. * So we only provide Linux version here.
  269. */
  270. double _TLIBC_CDECL_ nexttoward(double, long double);
  271. float _TLIBC_CDECL_ nexttowardf(float, long double);
  272. long double _TLIBC_CDECL_ nexttowardl(long double, long double);
  273. /*
  274. * Library implementation
  275. */
  276. int _TLIBC_CDECL_ __fpclassify(double);
  277. int _TLIBC_CDECL_ __fpclassifyf(float);
  278. int _TLIBC_CDECL_ __isfinite(double);
  279. int _TLIBC_CDECL_ __isfinitef(float);
  280. int _TLIBC_CDECL_ __isinf(double);
  281. int _TLIBC_CDECL_ __isinff(float);
  282. int _TLIBC_CDECL_ __isnan(double);
  283. int _TLIBC_CDECL_ __isnanf(float);
  284. int _TLIBC_CDECL_ __isnormal(double);
  285. int _TLIBC_CDECL_ __isnormalf(float);
  286. int _TLIBC_CDECL_ __signbit(double);
  287. int _TLIBC_CDECL_ __signbitf(float);
  288. int _TLIBC_CDECL_ __fpclassifyl(long double);
  289. int _TLIBC_CDECL_ __isfinitel(long double);
  290. int _TLIBC_CDECL_ __isinfl(long double);
  291. int _TLIBC_CDECL_ __isnanl(long double);
  292. int _TLIBC_CDECL_ __isnormall(long double);
  293. int _TLIBC_CDECL_ __signbitl(long double);
  294. /*
  295. * Non-C99 functions.
  296. */
  297. double _TLIBC_CDECL_ drem(double, double);
  298. double _TLIBC_CDECL_ exp10(double);
  299. double _TLIBC_CDECL_ gamma(double);
  300. double _TLIBC_CDECL_ gamma_r(double, int *);
  301. double _TLIBC_CDECL_ j0(double);
  302. double _TLIBC_CDECL_ j1(double);
  303. double _TLIBC_CDECL_ jn(int, double);
  304. double _TLIBC_CDECL_ lgamma_r(double, int *);
  305. double _TLIBC_CDECL_ pow10(double);
  306. double _TLIBC_CDECL_ scalb(double, double);
  307. /* C99 Macro signbit.*/
  308. double _TLIBC_CDECL_ significand(double);
  309. void _TLIBC_CDECL_ sincos(double, double *, double *);
  310. double _TLIBC_CDECL_ y0(double);
  311. double _TLIBC_CDECL_ y1(double);
  312. double _TLIBC_CDECL_ yn(int, double);
  313. /* C99 Macro isinf.*/
  314. /* C99 Macro isnan.*/
  315. int _TLIBC_CDECL_ finite(double);
  316. float _TLIBC_CDECL_ dremf(float, float);
  317. float _TLIBC_CDECL_ exp10f(float);
  318. float _TLIBC_CDECL_ gammaf(float);
  319. float _TLIBC_CDECL_ gammaf_r(float, int *);
  320. float _TLIBC_CDECL_ j0f(float);
  321. float _TLIBC_CDECL_ j1f(float);
  322. float _TLIBC_CDECL_ jnf(int, float);
  323. float _TLIBC_CDECL_ lgammaf_r(float, int *);
  324. float _TLIBC_CDECL_ pow10f(float);
  325. float _TLIBC_CDECL_ scalbf(float, float);
  326. int _TLIBC_CDECL_ signbitf(float);
  327. float _TLIBC_CDECL_ significandf(float);
  328. void _TLIBC_CDECL_ sincosf(float, float *, float *);
  329. float _TLIBC_CDECL_ y0f(float);
  330. float _TLIBC_CDECL_ y1f(float);
  331. float _TLIBC_CDECL_ ynf(int, float);
  332. int _TLIBC_CDECL_ finitef(float);
  333. int _TLIBC_CDECL_ isinff(float);
  334. int _TLIBC_CDECL_ isnanf(float);
  335. long double _TLIBC_CDECL_ dreml(long double, long double);
  336. long double _TLIBC_CDECL_ exp10l(long double);
  337. long double _TLIBC_CDECL_ gammal(long double);
  338. long double _TLIBC_CDECL_ gammal_r(long double, int *);
  339. long double _TLIBC_CDECL_ j0l(long double);
  340. long double _TLIBC_CDECL_ j1l(long double);
  341. long double _TLIBC_CDECL_ jnl(int, long double);
  342. long double _TLIBC_CDECL_ lgammal_r(long double, int *);
  343. long double _TLIBC_CDECL_ pow10l(long double);
  344. long double _TLIBC_CDECL_ scalbl(long double, long double);
  345. int _TLIBC_CDECL_ signbitl(long double);
  346. long double _TLIBC_CDECL_ significandl(long double);
  347. void _TLIBC_CDECL_ sincosl(long double, long double *, long double *);
  348. long double _TLIBC_CDECL_ y1l(long double);
  349. long double _TLIBC_CDECL_ y0l(long double);
  350. long double _TLIBC_CDECL_ ynl(int, long double);
  351. int _TLIBC_CDECL_ finitel(long double);
  352. int _TLIBC_CDECL_ isinfl(long double);
  353. int _TLIBC_CDECL_ isnanl(long double);
  354. /*
  355. * TODO: From Intel Decimal Floating-Point Math Library
  356. * signbitd32/signbitd64/signbitd128, finited32/finited64/finited128
  357. * isinfd32/isinfd64/isinfd128, isnand32/isnand64/isnand128
  358. */
  359. #if defined(__cplusplus)
  360. /* Clang does not support decimal floating point types.
  361. *
  362. * c.f.:
  363. * http://clang.llvm.org/docs/UsersManual.html#gcc-extensions-not-implemented-yet
  364. */
  365. #if !defined(__clang__)
  366. typedef float _Decimal32 __attribute__((mode(SD)));
  367. typedef float _Decimal64 __attribute__((mode(DD)));
  368. typedef float _Decimal128 __attribute__((mode(TD)));
  369. #endif
  370. #endif
  371. __END_DECLS
  372. #endif /* !_MATH_H_ */