openlibm.h 13 KB

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