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