openlibm.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  1. /*
  2. * ====================================================
  3. * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
  4. *
  5. * Developed at SunPro, a Sun Microsystems, Inc. business.
  6. * Permission to use, copy, modify, and distribute this
  7. * software is freely granted, provided that this notice
  8. * is preserved.
  9. * ====================================================
  10. */
  11. /*
  12. * from: @(#)fdlibm.h 5.1 93/09/24
  13. * $FreeBSD: src/lib/msun/src/math.h,v 1.80 2011/03/12 16:50:39 kargl Exp $
  14. */
  15. #ifndef _MATH_H_
  16. #define _MATH_H_
  17. #include <sys/cdefs.h>
  18. #include <sys/_types.h>
  19. #include <machine/_limits.h>
  20. /*
  21. * ANSI/POSIX
  22. */
  23. extern const union __infinity_un {
  24. unsigned char __uc[8];
  25. double __ud;
  26. } __infinity;
  27. extern const union __nan_un {
  28. unsigned char __uc[sizeof(float)];
  29. float __uf;
  30. } __nan;
  31. //#if __GNUC_PREREQ__(3, 3) || (defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 800)
  32. #define __MATH_BUILTIN_CONSTANTS
  33. //#endif
  34. //#if __GNUC_PREREQ__(3, 0) && !defined(__INTEL_COMPILER)
  35. #define __MATH_BUILTIN_RELOPS
  36. //#endif
  37. #ifdef __MATH_BUILTIN_CONSTANTS
  38. #define HUGE_VAL __builtin_huge_val()
  39. #else
  40. #define HUGE_VAL (__infinity.__ud)
  41. #endif
  42. #if __ISO_C_VISIBLE >= 1999
  43. #define FP_ILOGB0 (-__INT_MAX)
  44. #define FP_ILOGBNAN __INT_MAX
  45. #ifdef __MATH_BUILTIN_CONSTANTS
  46. #define HUGE_VALF __builtin_huge_valf()
  47. #define HUGE_VALL __builtin_huge_vall()
  48. #define INFINITY __builtin_inff()
  49. #define NAN __builtin_nanf("")
  50. #else
  51. #define HUGE_VALF (float)HUGE_VAL
  52. #define HUGE_VALL (long double)HUGE_VAL
  53. #define INFINITY HUGE_VALF
  54. #define NAN (__nan.__uf)
  55. #endif /* __MATH_BUILTIN_CONSTANTS */
  56. #define MATH_ERRNO 1
  57. #define MATH_ERREXCEPT 2
  58. #define math_errhandling MATH_ERREXCEPT
  59. /* XXX We need a <machine/math.h>. */
  60. #if defined(__ia64__) || defined(__sparc64__)
  61. #define FP_FAST_FMA 1
  62. #endif
  63. #ifdef __ia64__
  64. #define FP_FAST_FMAL 1
  65. #endif
  66. #define FP_FAST_FMAF 1
  67. /* Symbolic constants to classify floating point numbers. */
  68. #define FP_INFINITE 0x01
  69. #define FP_NAN 0x02
  70. #define FP_NORMAL 0x04
  71. #define FP_SUBNORMAL 0x08
  72. #define FP_ZERO 0x10
  73. #define fpclassify(x) \
  74. ((sizeof (x) == sizeof (float)) ? __fpclassifyf(x) \
  75. : (sizeof (x) == sizeof (double)) ? __fpclassifyd(x) \
  76. : __fpclassifyl(x))
  77. #define isfinite(x) \
  78. ((sizeof (x) == sizeof (float)) ? __isfinitef(x) \
  79. : (sizeof (x) == sizeof (double)) ? __isfinite(x) \
  80. : __isfinitel(x))
  81. #define isinf(x) \
  82. ((sizeof (x) == sizeof (float)) ? __isinff(x) \
  83. : (sizeof (x) == sizeof (double)) ? isinf(x) \
  84. : __isinfl(x))
  85. #define isnan(x) \
  86. ((sizeof (x) == sizeof (float)) ? __isnanf(x) \
  87. : (sizeof (x) == sizeof (double)) ? isnan(x) \
  88. : __isnanl(x))
  89. #define isnormal(x) \
  90. ((sizeof (x) == sizeof (float)) ? __isnormalf(x) \
  91. : (sizeof (x) == sizeof (double)) ? __isnormal(x) \
  92. : __isnormall(x))
  93. #ifdef __MATH_BUILTIN_RELOPS
  94. #define isgreater(x, y) __builtin_isgreater((x), (y))
  95. #define isgreaterequal(x, y) __builtin_isgreaterequal((x), (y))
  96. #define isless(x, y) __builtin_isless((x), (y))
  97. #define islessequal(x, y) __builtin_islessequal((x), (y))
  98. #define islessgreater(x, y) __builtin_islessgreater((x), (y))
  99. #define isunordered(x, y) __builtin_isunordered((x), (y))
  100. #else
  101. #define isgreater(x, y) (!isunordered((x), (y)) && (x) > (y))
  102. #define isgreaterequal(x, y) (!isunordered((x), (y)) && (x) >= (y))
  103. #define isless(x, y) (!isunordered((x), (y)) && (x) < (y))
  104. #define islessequal(x, y) (!isunordered((x), (y)) && (x) <= (y))
  105. #define islessgreater(x, y) (!isunordered((x), (y)) && \
  106. ((x) > (y) || (y) > (x)))
  107. #define isunordered(x, y) (isnan(x) || isnan(y))
  108. #endif /* __MATH_BUILTIN_RELOPS */
  109. #define signbit(x) \
  110. ((sizeof (x) == sizeof (float)) ? __signbitf(x) \
  111. : (sizeof (x) == sizeof (double)) ? __signbit(x) \
  112. : __signbitl(x))
  113. typedef __double_t double_t;
  114. typedef __float_t float_t;
  115. #endif /* __ISO_C_VISIBLE >= 1999 */
  116. /*
  117. * XOPEN/SVID
  118. */
  119. #if __BSD_VISIBLE || __XSI_VISIBLE
  120. #define M_E 2.7182818284590452354 /* e */
  121. #define M_LOG2E 1.4426950408889634074 /* log 2e */
  122. #define M_LOG10E 0.43429448190325182765 /* log 10e */
  123. #define M_LN2 0.69314718055994530942 /* log e2 */
  124. #define M_LN10 2.30258509299404568402 /* log e10 */
  125. #define M_PI 3.14159265358979323846 /* pi */
  126. #define M_PI_2 1.57079632679489661923 /* pi/2 */
  127. #define M_PI_4 0.78539816339744830962 /* pi/4 */
  128. #define M_1_PI 0.31830988618379067154 /* 1/pi */
  129. #define M_2_PI 0.63661977236758134308 /* 2/pi */
  130. #define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */
  131. #define M_SQRT2 1.41421356237309504880 /* sqrt(2) */
  132. #define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */
  133. #define MAXFLOAT ((float)3.40282346638528860e+38)
  134. extern int signgam;
  135. #endif /* __BSD_VISIBLE || __XSI_VISIBLE */
  136. #if __BSD_VISIBLE
  137. #if 0
  138. /* Old value from 4.4BSD-Lite math.h; this is probably better. */
  139. #define HUGE HUGE_VAL
  140. #else
  141. #define HUGE MAXFLOAT
  142. #endif
  143. #endif /* __BSD_VISIBLE */
  144. /*
  145. * Most of these functions depend on the rounding mode and have the side
  146. * effect of raising floating-point exceptions, so they are not declared
  147. * as __pure2. In C99, FENV_ACCESS affects the purity of these functions.
  148. */
  149. __BEGIN_DECLS
  150. /*
  151. * ANSI/POSIX
  152. */
  153. int __fpclassifyd(double) __pure2;
  154. int __fpclassifyf(float) __pure2;
  155. int __fpclassifyl(long double) __pure2;
  156. int __isfinitef(float) __pure2;
  157. int __isfinite(double) __pure2;
  158. int __isfinitel(long double) __pure2;
  159. int __isinff(float) __pure2;
  160. int __isinfl(long double) __pure2;
  161. int __isnanf(float) __pure2;
  162. int __isnanl(long double) __pure2;
  163. int __isnormalf(float) __pure2;
  164. int __isnormal(double) __pure2;
  165. int __isnormall(long double) __pure2;
  166. int __signbit(double) __pure2;
  167. int __signbitf(float) __pure2;
  168. int __signbitl(long double) __pure2;
  169. double acos(double);
  170. double asin(double);
  171. double atan(double);
  172. double atan2(double, double);
  173. double cos(double);
  174. double sin(double);
  175. double tan(double);
  176. double cosh(double);
  177. double sinh(double);
  178. double tanh(double);
  179. double exp(double);
  180. double frexp(double, int *); /* fundamentally !__pure2 */
  181. double ldexp(double, int);
  182. double log(double);
  183. double log10(double);
  184. double modf(double, double *); /* fundamentally !__pure2 */
  185. double pow(double, double);
  186. double sqrt(double);
  187. double ceil(double);
  188. double fabs(double) __pure2;
  189. double floor(double);
  190. double fmod(double, double);
  191. /*
  192. * These functions are not in C90.
  193. */
  194. #if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XSI_VISIBLE
  195. double acosh(double);
  196. double asinh(double);
  197. double atanh(double);
  198. double cbrt(double);
  199. double erf(double);
  200. double erfc(double);
  201. double exp2(double);
  202. double expm1(double);
  203. double fma(double, double, double);
  204. double hypot(double, double);
  205. int ilogb(double) __pure2;
  206. int (isinf)(double) __pure2;
  207. int (isnan)(double) __pure2;
  208. double lgamma(double);
  209. long long llrint(double);
  210. long long llround(double);
  211. double log1p(double);
  212. double log2(double);
  213. double logb(double);
  214. long lrint(double);
  215. long lround(double);
  216. double nan(const char *) __pure2;
  217. double nextafter(double, double);
  218. double remainder(double, double);
  219. double remquo(double, double, int *);
  220. double rint(double);
  221. #endif /* __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XSI_VISIBLE */
  222. #if __BSD_VISIBLE || __XSI_VISIBLE
  223. double j0(double);
  224. double j1(double);
  225. double jn(int, double);
  226. double y0(double);
  227. double y1(double);
  228. double yn(int, double);
  229. #if __XSI_VISIBLE <= 500 || __BSD_VISIBLE
  230. double gamma(double);
  231. #endif
  232. #if __XSI_VISIBLE <= 600 || __BSD_VISIBLE
  233. double scalb(double, double);
  234. #endif
  235. #endif /* __BSD_VISIBLE || __XSI_VISIBLE */
  236. #if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999
  237. double copysign(double, double) __pure2;
  238. double fdim(double, double);
  239. double fmax(double, double) __pure2;
  240. double fmin(double, double) __pure2;
  241. double nearbyint(double);
  242. double round(double);
  243. double scalbln(double, long);
  244. double scalbn(double, int);
  245. double tgamma(double);
  246. double trunc(double);
  247. #endif
  248. /*
  249. * BSD math library entry points
  250. */
  251. #if __BSD_VISIBLE
  252. double drem(double, double);
  253. int finite(double) __pure2;
  254. int isnanf(float) __pure2;
  255. /*
  256. * Reentrant version of gamma & lgamma; passes signgam back by reference
  257. * as the second argument; user must allocate space for signgam.
  258. */
  259. double gamma_r(double, int *);
  260. double lgamma_r(double, int *);
  261. /*
  262. * IEEE Test Vector
  263. */
  264. double significand(double);
  265. #endif /* __BSD_VISIBLE */
  266. /* float versions of ANSI/POSIX functions */
  267. #if __ISO_C_VISIBLE >= 1999
  268. float acosf(float);
  269. float asinf(float);
  270. float atanf(float);
  271. float atan2f(float, float);
  272. float cosf(float);
  273. float sinf(float);
  274. float tanf(float);
  275. float coshf(float);
  276. float sinhf(float);
  277. float tanhf(float);
  278. float exp2f(float);
  279. float expf(float);
  280. float expm1f(float);
  281. float frexpf(float, int *); /* fundamentally !__pure2 */
  282. int ilogbf(float) __pure2;
  283. float ldexpf(float, int);
  284. float log10f(float);
  285. float log1pf(float);
  286. float log2f(float);
  287. float logf(float);
  288. float modff(float, float *); /* fundamentally !__pure2 */
  289. float powf(float, float);
  290. float sqrtf(float);
  291. float ceilf(float);
  292. float fabsf(float) __pure2;
  293. float floorf(float);
  294. float fmodf(float, float);
  295. float roundf(float);
  296. float erff(float);
  297. float erfcf(float);
  298. float hypotf(float, float);
  299. float lgammaf(float);
  300. float tgammaf(float);
  301. float acoshf(float);
  302. float asinhf(float);
  303. float atanhf(float);
  304. float cbrtf(float);
  305. float logbf(float);
  306. float copysignf(float, float) __pure2;
  307. long long llrintf(float);
  308. long long llroundf(float);
  309. long lrintf(float);
  310. long lroundf(float);
  311. float nanf(const char *) __pure2;
  312. float nearbyintf(float);
  313. float nextafterf(float, float);
  314. float remainderf(float, float);
  315. float remquof(float, float, int *);
  316. float rintf(float);
  317. float scalblnf(float, long);
  318. float scalbnf(float, int);
  319. float truncf(float);
  320. float fdimf(float, float);
  321. float fmaf(float, float, float);
  322. float fmaxf(float, float) __pure2;
  323. float fminf(float, float) __pure2;
  324. #endif
  325. /*
  326. * float versions of BSD math library entry points
  327. */
  328. #if __BSD_VISIBLE
  329. float dremf(float, float);
  330. int finitef(float) __pure2;
  331. float gammaf(float);
  332. float j0f(float);
  333. float j1f(float);
  334. float jnf(int, float);
  335. float scalbf(float, float);
  336. float y0f(float);
  337. float y1f(float);
  338. float ynf(int, float);
  339. /*
  340. * Float versions of reentrant version of gamma & lgamma; passes
  341. * signgam back by reference as the second argument; user must
  342. * allocate space for signgam.
  343. */
  344. float gammaf_r(float, int *);
  345. float lgammaf_r(float, int *);
  346. /*
  347. * float version of IEEE Test Vector
  348. */
  349. float significandf(float);
  350. #endif /* __BSD_VISIBLE */
  351. /*
  352. * long double versions of ISO/POSIX math functions
  353. */
  354. #if __ISO_C_VISIBLE >= 1999
  355. #if 0
  356. long double acoshl(long double);
  357. #endif
  358. long double acosl(long double);
  359. #if 0
  360. long double asinhl(long double);
  361. #endif
  362. long double asinl(long double);
  363. long double atan2l(long double, long double);
  364. #if 0
  365. long double atanhl(long double);
  366. #endif
  367. long double atanl(long double);
  368. long double cbrtl(long double);
  369. long double ceill(long double);
  370. long double copysignl(long double, long double) __pure2;
  371. #if 0
  372. long double coshl(long double);
  373. #endif
  374. long double cosl(long double);
  375. #if 0
  376. long double erfcl(long double);
  377. long double erfl(long double);
  378. #endif
  379. long double exp2l(long double);
  380. #if 0
  381. long double expl(long double);
  382. long double expm1l(long double);
  383. #endif
  384. long double fabsl(long double) __pure2;
  385. long double fdiml(long double, long double);
  386. long double floorl(long double);
  387. long double fmal(long double, long double, long double);
  388. long double fmaxl(long double, long double) __pure2;
  389. long double fminl(long double, long double) __pure2;
  390. long double fmodl(long double, long double);
  391. long double frexpl(long double value, int *); /* fundamentally !__pure2 */
  392. long double hypotl(long double, long double);
  393. int ilogbl(long double) __pure2;
  394. long double ldexpl(long double, int);
  395. #if 0
  396. long double lgammal(long double);
  397. #endif
  398. long long llrintl(long double);
  399. long long llroundl(long double);
  400. #if 0
  401. long double log10l(long double);
  402. long double log1pl(long double);
  403. long double log2l(long double);
  404. #endif
  405. long double logbl(long double);
  406. #if 0
  407. long double logl(long double);
  408. #endif
  409. long lrintl(long double);
  410. long lroundl(long double);
  411. long double modfl(long double, long double *); /* fundamentally !__pure2 */
  412. long double nanl(const char *) __pure2;
  413. long double nearbyintl(long double);
  414. long double nextafterl(long double, long double);
  415. double nexttoward(double, long double);
  416. float nexttowardf(float, long double);
  417. long double nexttowardl(long double, long double);
  418. #if 0
  419. long double powl(long double, long double);
  420. #endif
  421. long double remainderl(long double, long double);
  422. long double remquol(long double, long double, int *);
  423. long double rintl(long double);
  424. long double roundl(long double);
  425. long double scalblnl(long double, long);
  426. long double scalbnl(long double, int);
  427. #if 0
  428. long double sinhl(long double);
  429. #endif
  430. long double sinl(long double);
  431. long double sqrtl(long double);
  432. #if 0
  433. long double tanhl(long double);
  434. #endif
  435. long double tanl(long double);
  436. #if 0
  437. long double tgammal(long double);
  438. #endif
  439. long double truncl(long double);
  440. #endif /* __ISO_C_VISIBLE >= 1999 */
  441. __END_DECLS
  442. #endif /* !_MATH_H_ */