openlibm_math.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513
  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. /*
  171. * ANSI/POSIX
  172. */
  173. int __fpclassifyd(double) __pure2;
  174. int __fpclassifyf(float) __pure2;
  175. int __fpclassifyl(long double) __pure2;
  176. int __isfinitef(float) __pure2;
  177. int __isfinite(double) __pure2;
  178. int __isfinitel(long double) __pure2;
  179. int __isinff(float) __pure2;
  180. int __isinfl(long double) __pure2;
  181. int __isnanf(float) __pure2;
  182. int __isnanl(long double) __pure2;
  183. int __isnormalf(float) __pure2;
  184. int __isnormal(double) __pure2;
  185. int __isnormall(long double) __pure2;
  186. int __signbit(double) __pure2;
  187. int __signbitf(float) __pure2;
  188. int __signbitl(long double) __pure2;
  189. double acos(double);
  190. double asin(double);
  191. double atan(double);
  192. double atan2(double, double);
  193. double cos(double);
  194. double sin(double);
  195. double tan(double);
  196. double cosh(double);
  197. double sinh(double);
  198. double tanh(double);
  199. double exp(double);
  200. double frexp(double, int *); /* fundamentally !__pure2 */
  201. double ldexp(double, int);
  202. double log(double);
  203. double log10(double);
  204. double modf(double, double *); /* fundamentally !__pure2 */
  205. double pow(double, double);
  206. double sqrt(double);
  207. double ceil(double);
  208. double fabs(double) __pure2;
  209. double floor(double);
  210. double fmod(double, double);
  211. /*
  212. * These functions are not in C90.
  213. */
  214. #if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XSI_VISIBLE
  215. double acosh(double);
  216. double asinh(double);
  217. double atanh(double);
  218. double cbrt(double);
  219. double erf(double);
  220. double erfc(double);
  221. double exp2(double);
  222. double expm1(double);
  223. double fma(double, double, double);
  224. double hypot(double, double);
  225. int ilogb(double) __pure2;
  226. int (isinf)(double) __pure2;
  227. int (isnan)(double) __pure2;
  228. double lgamma(double);
  229. long long llrint(double);
  230. long long llround(double);
  231. double log1p(double);
  232. double log2(double);
  233. double logb(double);
  234. long lrint(double);
  235. long lround(double);
  236. double nan(const char *) __pure2;
  237. double nextafter(double, double);
  238. double remainder(double, double);
  239. double remquo(double, double, int *);
  240. double rint(double);
  241. #endif /* __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XSI_VISIBLE */
  242. #if __BSD_VISIBLE || __XSI_VISIBLE
  243. double j0(double);
  244. double j1(double);
  245. double jn(int, double);
  246. double y0(double);
  247. double y1(double);
  248. double yn(int, double);
  249. #if __XSI_VISIBLE <= 500 || __BSD_VISIBLE
  250. double gamma(double);
  251. #endif
  252. #if __XSI_VISIBLE <= 600 || __BSD_VISIBLE
  253. double scalb(double, double);
  254. #endif
  255. #endif /* __BSD_VISIBLE || __XSI_VISIBLE */
  256. #if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999
  257. double copysign(double, double) __pure2;
  258. double fdim(double, double);
  259. double fmax(double, double) __pure2;
  260. double fmin(double, double) __pure2;
  261. double nearbyint(double);
  262. double round(double);
  263. double scalbln(double, long);
  264. double scalbn(double, int);
  265. double tgamma(double);
  266. double trunc(double);
  267. #endif
  268. /*
  269. * BSD math library entry points
  270. */
  271. #if __BSD_VISIBLE
  272. double drem(double, double);
  273. int finite(double) __pure2;
  274. int isnanf(float) __pure2;
  275. /*
  276. * Reentrant version of gamma & lgamma; passes signgam back by reference
  277. * as the second argument; user must allocate space for signgam.
  278. */
  279. double gamma_r(double, int *);
  280. double lgamma_r(double, int *);
  281. /*
  282. * Single sine/cosine function.
  283. */
  284. void sincos(double, double *, double *);
  285. /*
  286. * IEEE Test Vector
  287. */
  288. double significand(double);
  289. #endif /* __BSD_VISIBLE */
  290. /* float versions of ANSI/POSIX functions */
  291. #if __ISO_C_VISIBLE >= 1999
  292. float acosf(float);
  293. float asinf(float);
  294. float atanf(float);
  295. float atan2f(float, float);
  296. float cosf(float);
  297. float sinf(float);
  298. float tanf(float);
  299. float coshf(float);
  300. float sinhf(float);
  301. float tanhf(float);
  302. float exp2f(float);
  303. float expf(float);
  304. float expm1f(float);
  305. float frexpf(float, int *); /* fundamentally !__pure2 */
  306. int ilogbf(float) __pure2;
  307. float ldexpf(float, int);
  308. float log10f(float);
  309. float log1pf(float);
  310. float log2f(float);
  311. float logf(float);
  312. float modff(float, float *); /* fundamentally !__pure2 */
  313. float powf(float, float);
  314. float sqrtf(float);
  315. float ceilf(float);
  316. float fabsf(float) __pure2;
  317. float floorf(float);
  318. float fmodf(float, float);
  319. float roundf(float);
  320. float erff(float);
  321. float erfcf(float);
  322. float hypotf(float, float);
  323. float lgammaf(float);
  324. float tgammaf(float);
  325. float acoshf(float);
  326. float asinhf(float);
  327. float atanhf(float);
  328. float cbrtf(float);
  329. float logbf(float);
  330. float copysignf(float, float) __pure2;
  331. long long llrintf(float);
  332. long long llroundf(float);
  333. long lrintf(float);
  334. long lroundf(float);
  335. float nanf(const char *) __pure2;
  336. float nearbyintf(float);
  337. float nextafterf(float, float);
  338. float remainderf(float, float);
  339. float remquof(float, float, int *);
  340. float rintf(float);
  341. float scalblnf(float, long);
  342. float scalbnf(float, int);
  343. float truncf(float);
  344. float fdimf(float, float);
  345. float fmaf(float, float, float);
  346. float fmaxf(float, float) __pure2;
  347. float fminf(float, float) __pure2;
  348. #endif
  349. /*
  350. * float versions of BSD math library entry points
  351. */
  352. #if __BSD_VISIBLE
  353. float dremf(float, float);
  354. int finitef(float) __pure2;
  355. float gammaf(float);
  356. float j0f(float);
  357. float j1f(float);
  358. float jnf(int, float);
  359. float scalbf(float, float);
  360. float y0f(float);
  361. float y1f(float);
  362. float ynf(int, float);
  363. /*
  364. * Float versions of reentrant version of gamma & lgamma; passes
  365. * signgam back by reference as the second argument; user must
  366. * allocate space for signgam.
  367. */
  368. float gammaf_r(float, int *);
  369. float lgammaf_r(float, int *);
  370. /*
  371. * Single sine/cosine function.
  372. */
  373. void sincosf(float, float *, float *);
  374. /*
  375. * float version of IEEE Test Vector
  376. */
  377. float significandf(float);
  378. #endif /* __BSD_VISIBLE */
  379. /*
  380. * long double versions of ISO/POSIX math functions
  381. */
  382. #if __ISO_C_VISIBLE >= 1999
  383. long double acoshl(long double);
  384. long double acosl(long double);
  385. long double asinhl(long double);
  386. long double asinl(long double);
  387. long double atan2l(long double, long double);
  388. long double atanhl(long double);
  389. long double atanl(long double);
  390. long double cbrtl(long double);
  391. long double ceill(long double);
  392. long double copysignl(long double, long double) __pure2;
  393. long double coshl(long double);
  394. long double cosl(long double);
  395. long double erfcl(long double);
  396. long double erfl(long double);
  397. long double exp2l(long double);
  398. long double expl(long double);
  399. long double expm1l(long double);
  400. long double fabsl(long double) __pure2;
  401. long double fdiml(long double, long double);
  402. long double floorl(long double);
  403. long double fmal(long double, long double, long double);
  404. long double fmaxl(long double, long double) __pure2;
  405. long double fminl(long double, long double) __pure2;
  406. long double fmodl(long double, long double);
  407. long double frexpl(long double value, int *); /* fundamentally !__pure2 */
  408. long double hypotl(long double, long double);
  409. int ilogbl(long double) __pure2;
  410. long double ldexpl(long double, int);
  411. long double lgammal(long double);
  412. long long llrintl(long double);
  413. long long llroundl(long double);
  414. long double log10l(long double);
  415. long double log1pl(long double);
  416. long double log2l(long double);
  417. long double logbl(long double);
  418. long double logl(long double);
  419. long lrintl(long double);
  420. long lroundl(long double);
  421. long double modfl(long double, long double *); /* fundamentally !__pure2 */
  422. long double nanl(const char *) __pure2;
  423. long double nearbyintl(long double);
  424. long double nextafterl(long double, long double);
  425. double nexttoward(double, long double);
  426. float nexttowardf(float, long double);
  427. long double nexttowardl(long double, long double);
  428. long double powl(long double, long double);
  429. long double remainderl(long double, long double);
  430. long double remquol(long double, long double, int *);
  431. long double rintl(long double);
  432. long double roundl(long double);
  433. long double scalblnl(long double, long);
  434. long double scalbnl(long double, int);
  435. long double sinhl(long double);
  436. long double sinl(long double);
  437. long double sqrtl(long double);
  438. long double tanhl(long double);
  439. long double tanl(long double);
  440. long double tgammal(long double);
  441. long double truncl(long double);
  442. #endif /* __ISO_C_VISIBLE >= 1999 */
  443. /* Reentrant version of lgammal. */
  444. #if __BSD_VISIBLE
  445. long double lgammal_r(long double, int *);
  446. /*
  447. * Single sine/cosine function.
  448. */
  449. void sincosl(long double, long double *, long double *);
  450. #endif /* __BSD_VISIBLE */
  451. #if defined(__cplusplus)
  452. }
  453. #endif
  454. #endif /* !OPENLIBM_MATH_H */
  455. #endif /* OPENLIBM_USE_HOST_MATH_H */