math.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  1. /* mconf.h
  2. * <math.h>
  3. * ISO/IEC 9899:1999 -- Programming Languages C: 7.12 Mathematics
  4. * Derived from the Cephes Math Library Release 2.3
  5. * Copyright 1984, 1987, 1989, 1995 by Stephen L. Moshier
  6. *
  7. *
  8. * DESCRIPTION:
  9. *
  10. * The file also includes a conditional assembly definition
  11. * for the type of computer arithmetic (IEEE, DEC, Motorola
  12. * IEEE, or UNKnown).
  13. *
  14. * For Digital Equipment PDP-11 and VAX computers, certain
  15. * IBM systems, and others that use numbers with a 56-bit
  16. * significand, the symbol DEC should be defined. In this
  17. * mode, most floating point constants are given as arrays
  18. * of octal integers to eliminate decimal to binary conversion
  19. * errors that might be introduced by the compiler.
  20. *
  21. * For little-endian computers, such as IBM PC, that follow the
  22. * IEEE Standard for Binary Floating Point Arithmetic (ANSI/IEEE
  23. * Std 754-1985), the symbol IBMPC should be defined. These
  24. * numbers have 53-bit significands. In this mode, constants
  25. * are provided as arrays of hexadecimal 16 bit integers.
  26. *
  27. * Big-endian IEEE format is denoted MIEEE. On some RISC
  28. * systems such as Sun SPARC, double precision constants
  29. * must be stored on 8-byte address boundaries. Since integer
  30. * arrays may be aligned differently, the MIEEE configuration
  31. * may fail on such machines.
  32. *
  33. * To accommodate other types of computer arithmetic, all
  34. * constants are also provided in a normal decimal radix
  35. * which one can hope are correctly converted to a suitable
  36. * format by the available C language compiler. To invoke
  37. * this mode, define the symbol UNK.
  38. *
  39. * An important difference among these modes is a predefined
  40. * set of machine arithmetic constants for each. The numbers
  41. * MACHEP (the machine roundoff error), MAXNUM (largest number
  42. * represented), and several other parameters are preset by
  43. * the configuration symbol. Check the file const.c to
  44. * ensure that these values are correct for your computer.
  45. *
  46. * Configurations NANS, INFINITIES, MINUSZERO, and DENORMAL
  47. * may fail on many systems. Verify that they are supposed
  48. * to work on your computer.
  49. */
  50. #ifndef _MATH_H
  51. #define _MATH_H 1
  52. #include <features.h>
  53. #include <bits/huge_val.h>
  54. /* Type of computer arithmetic */
  55. /* PDP-11, Pro350, VAX:
  56. */
  57. /* #define DEC 1 */
  58. /* Intel IEEE, low order words come first:
  59. */
  60. /* #define IBMPC 1 */
  61. /* Motorola IEEE, high order words come first
  62. * (Sun 680x0 workstation):
  63. */
  64. /* #define MIEEE 1 */
  65. /* UNKnown arithmetic, invokes coefficients given in
  66. * normal decimal format. Beware of range boundary
  67. * problems (MACHEP, MAXLOG, etc. in const.c) and
  68. * roundoff problems in pow.c:
  69. * (Sun SPARCstation)
  70. */
  71. #define UNK 1
  72. /* Define if the `long double' type works. */
  73. #define HAVE_LONG_DOUBLE 1
  74. /* Define as the return type of signal handlers (int or void). */
  75. #define RETSIGTYPE void
  76. /* Define if you have the ANSI C header files. */
  77. #define STDC_HEADERS 1
  78. /* Define if your processor stores words with the most significant
  79. byte first (like Motorola and SPARC, unlike Intel and VAX). */
  80. /* #undef WORDS_BIGENDIAN */
  81. /* Define if floating point words are bigendian. */
  82. /* #undef FLOAT_WORDS_BIGENDIAN */
  83. /* The number of bytes in a int. */
  84. #define SIZEOF_INT 4
  85. /* Define if you have the <string.h> header file. */
  86. #define HAVE_STRING_H 1
  87. /* Define this `volatile' if your compiler thinks
  88. * that floating point arithmetic obeys the associative
  89. * and distributive laws. It will defeat some optimizations
  90. * (but probably not enough of them).
  91. *
  92. * #define VOLATILE volatile
  93. */
  94. #define VOLATILE
  95. /* For 12-byte long doubles on an i386, pad a 16-bit short 0
  96. * to the end of real constants initialized by integer arrays.
  97. *
  98. * #define XPD 0,
  99. *
  100. * Otherwise, the type is 10 bytes long and XPD should be
  101. * defined blank (e.g., Microsoft C).
  102. *
  103. * #define XPD
  104. */
  105. #define XPD 0,
  106. /* Define to support tiny denormal numbers, else undefine. */
  107. #define DENORMAL 1
  108. /* Define to ask for infinity support, else undefine. */
  109. #define INFINITIES 1
  110. /* Define to ask for support of numbers that are Not-a-Number,
  111. else undefine. This may automatically define INFINITIES in some files. */
  112. #define NANS 1
  113. /* Define to distinguish between -0.0 and +0.0. */
  114. #define MINUSZERO 1
  115. /* Define 1 for ANSI C atan2() function
  116. and ANSI prototypes for float arguments.
  117. See atan.c and clog.c. */
  118. #define ANSIC 1
  119. #define ANSIPROT 1
  120. /* Constant definitions for math error conditions */
  121. #define DOMAIN 1 /* argument domain error */
  122. #define SING 2 /* argument singularity */
  123. #define OVERFLOW 3 /* overflow range error */
  124. #define UNDERFLOW 4 /* underflow range error */
  125. #define TLOSS 5 /* total loss of precision */
  126. #define PLOSS 6 /* partial loss of precision */
  127. #define EDOM 33
  128. #define ERANGE 34
  129. /* Complex numeral. */
  130. #ifdef __UCLIBC_HAS_LIBM_DOUBLE__
  131. typedef struct
  132. {
  133. double r;
  134. double i;
  135. } cmplx;
  136. #endif
  137. #ifdef __UCLIBC_HAS_LIBM_FLOAT__
  138. typedef struct
  139. {
  140. float r;
  141. float i;
  142. } cmplxf;
  143. #endif
  144. #ifdef __UCLIBC_HAS_LIBM_LONG_DOUBLE__
  145. /* Long double complex numeral. */
  146. typedef struct
  147. {
  148. long double r;
  149. long double i;
  150. } cmplxl;
  151. #endif
  152. /* Variable for error reporting. See mtherr.c. */
  153. extern int mtherr(char *name, int code);
  154. extern int merror;
  155. /* If you define UNK, then be sure to set BIGENDIAN properly. */
  156. #include <endian.h>
  157. #if __BYTE_ORDER == __BIG_ENDIAN
  158. # define BIGENDIAN 1
  159. #else /* __BYTE_ORDER == __LITTLE_ENDIAN */
  160. # define BIGENDIAN 0
  161. #endif
  162. #define __USE_ISOC9X
  163. /* Get general and ISO C 9X specific information. */
  164. #include <bits/mathdef.h>
  165. #undef INFINITY
  166. #undef DECIMAL_DIG
  167. #undef FP_ILOGB0
  168. #undef FP_ILOGBNAN
  169. /* Get the architecture specific values describing the floating-point
  170. evaluation. The following symbols will get defined:
  171. float_t floating-point type at least as wide as `float' used
  172. to evaluate `float' expressions
  173. double_t floating-point type at least as wide as `double' used
  174. to evaluate `double' expressions
  175. FLT_EVAL_METHOD
  176. Defined to
  177. 0 if `float_t' is `float' and `double_t' is `double'
  178. 1 if `float_t' and `double_t' are `double'
  179. 2 if `float_t' and `double_t' are `long double'
  180. else `float_t' and `double_t' are unspecified
  181. INFINITY representation of the infinity value of type `float'
  182. FP_FAST_FMA
  183. FP_FAST_FMAF
  184. FP_FAST_FMAL
  185. If defined it indicates that the `fma' function
  186. generally executes about as fast as a multiply and an add.
  187. This macro is defined only iff the `fma' function is
  188. implemented directly with a hardware multiply-add instructions.
  189. FP_ILOGB0 Expands to a value returned by `ilogb (0.0)'.
  190. FP_ILOGBNAN Expands to a value returned by `ilogb (NAN)'.
  191. DECIMAL_DIG Number of decimal digits supported by conversion between
  192. decimal and all internal floating-point formats.
  193. */
  194. /* All floating-point numbers can be put in one of these categories. */
  195. enum
  196. {
  197. FP_NAN,
  198. # define FP_NAN FP_NAN
  199. FP_INFINITE,
  200. # define FP_INFINITE FP_INFINITE
  201. FP_ZERO,
  202. # define FP_ZERO FP_ZERO
  203. FP_SUBNORMAL,
  204. # define FP_SUBNORMAL FP_SUBNORMAL
  205. FP_NORMAL
  206. # define FP_NORMAL FP_NORMAL
  207. };
  208. /* Return number of classification appropriate for X. */
  209. #ifdef __UCLIBC_HAS_LIBM_DOUBLE__
  210. # define fpclassify(x) \
  211. (sizeof (x) == sizeof (float) ? \
  212. __fpclassifyf (x) \
  213. : sizeof (x) == sizeof (double) ? \
  214. __fpclassify (x) : __fpclassifyl (x))
  215. #else
  216. # define fpclassify(x) \
  217. (sizeof (x) == sizeof (float) ? __fpclassifyf (x) : __fpclassify (x))
  218. #endif
  219. #ifdef __UCLIBC_HAS_LIBM_DOUBLE__
  220. /* Return nonzero value if sign of X is negative. */
  221. extern int signbit(double x);
  222. /* Return nonzero value if X is not +-Inf or NaN. */
  223. extern int isfinite(double x);
  224. /* Return nonzero value if X is neither zero, subnormal, Inf, nor NaN. */
  225. # define isnormal(x) (fpclassify (x) == FP_NORMAL)
  226. /* Return nonzero value if X is a NaN */
  227. extern int isnan(double x);
  228. #define isinf(x) \
  229. (sizeof (x) == sizeof (float) ? \
  230. __isinff (x) \
  231. : sizeof (x) == sizeof (double) ? \
  232. __isinf (x) : __isinfl (x))
  233. #else
  234. # define isinf(x) \
  235. (sizeof (x) == sizeof (float) ? __isinff (x) : __isinf (x))
  236. #endif
  237. #ifdef __UCLIBC_HAS_LIBM_LONG_DOUBLE__
  238. /* Return nonzero value if sign of X is negative. */
  239. extern int signbitl(long double x);
  240. /* Return nonzero value if X is not +-Inf or NaN. */
  241. extern int isfinitel(long double x);
  242. /* Return nonzero value if X is a NaN */
  243. extern int isnanl(long double x);
  244. #endif
  245. /* Some useful constants. */
  246. #if defined __USE_BSD || defined __USE_XOPEN
  247. # define M_E 2.7182818284590452354 /* e */
  248. # define M_LOG2E 1.4426950408889634074 /* log_2 e */
  249. # define M_LOG10E 0.43429448190325182765 /* log_10 e */
  250. # define M_LN2 0.69314718055994530942 /* log_e 2 */
  251. # define M_LN10 2.30258509299404568402 /* log_e 10 */
  252. # define M_PI 3.14159265358979323846 /* pi */
  253. # define M_PI_2 1.57079632679489661923 /* pi/2 */
  254. # define M_PI_4 0.78539816339744830962 /* pi/4 */
  255. # define M_1_PI 0.31830988618379067154 /* 1/pi */
  256. # define M_2_PI 0.63661977236758134308 /* 2/pi */
  257. # define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */
  258. # define M_SQRT2 1.41421356237309504880 /* sqrt(2) */
  259. # define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */
  260. #endif
  261. #ifdef __USE_GNU
  262. # define M_El M_E
  263. # define M_LOG2El M_LOG2E
  264. # define M_LOG10El M_LOG10E
  265. # define M_LN2l M_LN2
  266. # define M_LN10l M_LN10
  267. # define M_PIl M_PI
  268. # define M_PI_2l M_PI_2
  269. # define M_PI_4l M_PI_4
  270. # define M_1_PIl M_1_PI
  271. # define M_2_PIl M_2_PI
  272. # define M_2_SQRTPIl M_2_SQRTPI
  273. # define M_SQRT2l M_SQRT2
  274. # define M_SQRT1_2l M_SQRT1_2
  275. #endif
  276. #ifdef __UCLIBC_HAS_LIBM_DOUBLE__
  277. /* 7.12.4 Trigonometric functions */
  278. extern double acos(double x);
  279. extern double asin(double x);
  280. extern double atan(double x);
  281. extern double atan2(double y, double x);
  282. extern double cos(double x);
  283. extern double sin(double x);
  284. extern double tan(double x);
  285. /* 7.12.5 Hyperbolic functions */
  286. extern double acosh(double x);
  287. extern double asinh(double x);
  288. extern double atanh(double x);
  289. extern double cosh(double x);
  290. extern double sinh(double x);
  291. extern double tanh(double x);
  292. /* 7.12.6 Exponential and logarithmic functions */
  293. extern double exp(double x);
  294. extern double exp2(double x);
  295. extern double expm1(double x);
  296. extern double frexp(double value, int *exp);
  297. extern int ilogb(double x);
  298. extern double ldexp(double x, int exp);
  299. extern double log(double x);
  300. extern double log10(double x);
  301. extern double log1p(double x);
  302. extern double log2(double x);
  303. extern double logb(double x);
  304. extern double modf(double value, double *iptr);
  305. extern double scalbn(double x, int n);
  306. extern double scalbln(double x, long int n);
  307. /* 7.12.7 Power and absolute-value functions */
  308. extern double fabs(double x);
  309. extern double hypot(double x, double y);
  310. extern double pow(double x, double y);
  311. extern double sqrt(double x);
  312. /* 7.12.8 Error and gamma functions */
  313. extern double erf(double x);
  314. extern double erfc(double x);
  315. extern double lgamma(double x);
  316. extern double tgamma(double x);
  317. /* 7.12.9 Nearest integer functions */
  318. extern double ceil(double x);
  319. extern double floor(double x);
  320. extern double nearbyint(double x);
  321. extern double rint(double x);
  322. extern long int lrint(double x);
  323. extern long long int llrint(double x);
  324. extern double round(double x);
  325. extern long int lround(double x);
  326. extern long long int llround(double x);
  327. extern double trunc(double x);
  328. /* 7.12.10 Remainder functions */
  329. extern double fmod(double x, double y);
  330. extern double remainder(double x, double y);
  331. extern double remquo(double x, double y, int *quo);
  332. /* 7.12.11 Manipulation functions */
  333. extern double copysign(double x, double y);
  334. extern double nan(const char *tagp);
  335. extern double nextafter(double x, double y);
  336. /* 7.12.12 Maximum, minimum, and positive difference functions */
  337. extern double fdim(double x, double y);
  338. extern double fmax(double x, double y);
  339. extern double fmin(double x, double y);
  340. /* 7.12.13 Floating multiply-add */
  341. extern double fma(double x, double y, double z);
  342. #endif
  343. #ifdef __UCLIBC_HAS_LIBM_FLOAT__
  344. /* 7.12.4 Trigonometric functions */
  345. extern float acosf(float x);
  346. extern float asinf(float x);
  347. extern float atanf(float x);
  348. extern float atan2f(float y, float x);
  349. extern float cosf(float x);
  350. extern float sinf(float x);
  351. extern float tanf(float x);
  352. /* 7.12.5 Hyperbolic functions */
  353. extern float acoshf(float x);
  354. extern float asinhf(float x);
  355. extern float atanhf(float x);
  356. extern float coshf(float x);
  357. extern float sinhf(float x);
  358. extern float tanhf(float x);
  359. /* 7.12.6 Exponential and logarithmic functions */
  360. extern float expf(float x);
  361. extern float exp2f(float x);
  362. extern float expm1f(float x);
  363. extern float frexpf(float value, int *exp);
  364. extern int ilogbf(float x);
  365. extern float ldexpf(float x, int exp);
  366. extern float logf(float x);
  367. extern float log10f(float x);
  368. extern float log1pf(float x);
  369. extern float log2f(float x);
  370. extern float logbf(float x);
  371. extern float modff(float value, float *iptr);
  372. extern float scalbnf(float x, int n);
  373. extern float scalblnf(float x, long int n);
  374. /* 7.12.7 Power and absolute-value functions */
  375. extern float fabsf(float x);
  376. extern float hypotf(float x, float y);
  377. extern float powf(float x, float y);
  378. extern float sqrtf(float x);
  379. /* 7.12.8 Error and gamma functions */
  380. extern float erff(float x);
  381. extern float erfcf(float x);
  382. extern float lgammaf(float x);
  383. extern float tgammaf(float x);
  384. /* 7.12.9 Nearest integer functions */
  385. extern float ceilf(float x);
  386. extern float floorf(float x);
  387. extern float nearbyintf(float x);
  388. extern float rintf(float x);
  389. extern long int lrintf(float x);
  390. extern long long int llrintf(float x);
  391. extern float roundf(float x);
  392. extern long int lroundf(float x);
  393. extern long long int llroundf(float x);
  394. extern float truncf(float x);
  395. /* 7.12.10 Remainder functions */
  396. extern float fmodf(float x, float y);
  397. extern float remainderf(float x, float y);
  398. extern float remquof(float x, float y, int *quo);
  399. /* 7.12.11 Manipulation functions */
  400. extern float copysignf(float x, float y);
  401. extern float nanf(const char *tagp);
  402. extern float nextafterf(float x, float y);
  403. /* 7.12.12 Maximum, minimum, and positive difference functions */
  404. extern float fdimf(float x, float y);
  405. extern float fmaxf(float x, float y);
  406. extern float fminf(float x, float y);
  407. /* 7.12.13 Floating multiply-add */
  408. extern float fmaf(float x, float y, float z);
  409. #endif
  410. #ifdef __UCLIBC_HAS_LIBM_LONG_DOUBLE__
  411. /* 7.12.4 Trigonometric functions */
  412. extern long double acosl(long double x);
  413. extern long double asinl(long double x);
  414. extern long double atanl(long double x);
  415. extern long double atan2l(long double y, long double x);
  416. extern long double cosl(long double x);
  417. extern long double sinl(long double x);
  418. extern long double tanl(long double x);
  419. /* 7.12.5 Hyperbolic functions */
  420. extern long double acoshl(long double x);
  421. extern long double asinhl(long double x);
  422. extern long double atanhl(long double x);
  423. extern long double coshl(long double x);
  424. extern long double sinhl(long double x);
  425. extern long double tanhl(long double x);
  426. /* 7.12.6 Exponential and logarithmic functions */
  427. extern long double expl(long double x);
  428. extern long double exp2l(long double x);
  429. extern long double expm1l(long double x);
  430. extern long double frexpl(long double value, int *exp);
  431. extern int ilogbl(long double x);
  432. extern long double ldexpl(long double x, int exp);
  433. extern long double logl(long double x);
  434. extern long double log10l(long double x);
  435. extern long double log1pl(long double x);
  436. extern long double log2l(long double x);
  437. extern long double logbl(long double x);
  438. extern long double modfl(long double value, long double *iptr);
  439. extern long double scalbnl(long double x, int n);
  440. extern long double scalblnl(long double x, long int n);
  441. /* 7.12.7 Power and absolute-value functions */
  442. extern long double fabsl(long double x);
  443. extern long double hypotl(long double x, long double y);
  444. extern long double powl(long double x, long double y);
  445. extern long double sqrtl(long double x);
  446. /* 7.12.8 Error and gamma functions */
  447. extern long double erfl(long double x);
  448. extern long double erfcl(long double x);
  449. extern long double lgammal(long double x);
  450. extern long double tgammal(long double x);
  451. /* 7.12.9 Nearest integer functions */
  452. extern long double ceill(long double x);
  453. extern long double floorl(long double x);
  454. extern long double nearbyintl(long double x);
  455. extern long double rintl(long double x);
  456. extern long int lrintl(long double x);
  457. extern long long int llrintl(long double x);
  458. extern long double roundl(long double x);
  459. extern long int lroundl(long double x);
  460. extern long long int llroundl(long double x);
  461. extern long double truncl(long double x);
  462. /* 7.12.10 Remainder functions */
  463. extern long double fmodl(long double x, long double y);
  464. extern long double remainderl(long double x, long double y);
  465. extern long double remquol(long double x, long double y, int *quo);
  466. /* 7.12.11 Manipulation functions */
  467. extern long double copysignl(long double x, long double y);
  468. extern long double nanl(const char *tagp);
  469. extern long double nextafterl(long double x, long double y);
  470. extern long double nexttowardl(long double x, long double y);
  471. /* 7.12.12 Maximum, minimum, and positive difference functions */
  472. extern long double fdiml(long double x, long double y);
  473. extern long double fmaxl(long double x, long double y);
  474. extern long double fminl(long double x, long double y);
  475. /* 7.12.13 Floating multiply-add */
  476. extern long double fmal(long double x, long double y, long double z);
  477. #endif
  478. /* 7.12.14 Comparison macros */
  479. # ifndef isgreater
  480. # define isgreater(x, y) \
  481. (__extension__ \
  482. ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y); \
  483. !isunordered (__x, __y) && __x > __y; }))
  484. # endif
  485. /* Return nonzero value if X is greater than or equal to Y. */
  486. # ifndef isgreaterequal
  487. # define isgreaterequal(x, y) \
  488. (__extension__ \
  489. ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y); \
  490. !isunordered (__x, __y) && __x >= __y; }))
  491. # endif
  492. /* Return nonzero value if X is less than Y. */
  493. # ifndef isless
  494. # define isless(x, y) \
  495. (__extension__ \
  496. ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y); \
  497. !isunordered (__x, __y) && __x < __y; }))
  498. # endif
  499. /* Return nonzero value if X is less than or equal to Y. */
  500. # ifndef islessequal
  501. # define islessequal(x, y) \
  502. (__extension__ \
  503. ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y); \
  504. !isunordered (__x, __y) && __x <= __y; }))
  505. # endif
  506. /* Return nonzero value if either X is less than Y or Y is less than X. */
  507. # ifndef islessgreater
  508. # define islessgreater(x, y) \
  509. (__extension__ \
  510. ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y); \
  511. !isunordered (__x, __y) && (__x < __y || __y < __x); }))
  512. # endif
  513. /* Return nonzero value if arguments are unordered. */
  514. # ifndef isunordered
  515. # define isunordered(u, v) \
  516. (__extension__ \
  517. ({ __typeof__(u) __u = (u); __typeof__(v) __v = (v); \
  518. fpclassify (__u) == FP_NAN || fpclassify (__v) == FP_NAN; }))
  519. # endif
  520. #endif /* math.h */