math.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  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. __BEGIN_DECLS
  154. extern int mtherr(char *name, int code);
  155. extern int merror;
  156. __END_DECLS
  157. /* If you define UNK, then be sure to set BIGENDIAN properly. */
  158. #include <endian.h>
  159. #if __BYTE_ORDER == __BIG_ENDIAN
  160. # define BIGENDIAN 1
  161. #else /* __BYTE_ORDER == __LITTLE_ENDIAN */
  162. # define BIGENDIAN 0
  163. #endif
  164. #define __USE_ISOC9X
  165. /* Get general and ISO C 9X specific information. */
  166. #include <bits/mathdef.h>
  167. #undef INFINITY
  168. #undef DECIMAL_DIG
  169. #undef FP_ILOGB0
  170. #undef FP_ILOGBNAN
  171. /* Get the architecture specific values describing the floating-point
  172. evaluation. The following symbols will get defined:
  173. float_t floating-point type at least as wide as `float' used
  174. to evaluate `float' expressions
  175. double_t floating-point type at least as wide as `double' used
  176. to evaluate `double' expressions
  177. FLT_EVAL_METHOD
  178. Defined to
  179. 0 if `float_t' is `float' and `double_t' is `double'
  180. 1 if `float_t' and `double_t' are `double'
  181. 2 if `float_t' and `double_t' are `long double'
  182. else `float_t' and `double_t' are unspecified
  183. INFINITY representation of the infinity value of type `float'
  184. FP_FAST_FMA
  185. FP_FAST_FMAF
  186. FP_FAST_FMAL
  187. If defined it indicates that the `fma' function
  188. generally executes about as fast as a multiply and an add.
  189. This macro is defined only iff the `fma' function is
  190. implemented directly with a hardware multiply-add instructions.
  191. FP_ILOGB0 Expands to a value returned by `ilogb (0.0)'.
  192. FP_ILOGBNAN Expands to a value returned by `ilogb (NAN)'.
  193. DECIMAL_DIG Number of decimal digits supported by conversion between
  194. decimal and all internal floating-point formats.
  195. */
  196. /* All floating-point numbers can be put in one of these categories. */
  197. enum
  198. {
  199. FP_NAN,
  200. # define FP_NAN FP_NAN
  201. FP_INFINITE,
  202. # define FP_INFINITE FP_INFINITE
  203. FP_ZERO,
  204. # define FP_ZERO FP_ZERO
  205. FP_SUBNORMAL,
  206. # define FP_SUBNORMAL FP_SUBNORMAL
  207. FP_NORMAL
  208. # define FP_NORMAL FP_NORMAL
  209. };
  210. /* Return number of classification appropriate for X. */
  211. #ifdef __UCLIBC_HAS_LIBM_DOUBLE__
  212. # define fpclassify(x) \
  213. (sizeof (x) == sizeof (float) ? \
  214. __fpclassifyf (x) \
  215. : sizeof (x) == sizeof (double) ? \
  216. __fpclassify (x) : __fpclassifyl (x))
  217. #else
  218. # define fpclassify(x) \
  219. (sizeof (x) == sizeof (float) ? __fpclassifyf (x) : __fpclassify (x))
  220. #endif
  221. __BEGIN_DECLS
  222. #ifdef __UCLIBC_HAS_LIBM_DOUBLE__
  223. /* Return nonzero value if sign of X is negative. */
  224. extern int signbit(double x);
  225. /* Return nonzero value if X is not +-Inf or NaN. */
  226. extern int isfinite(double x);
  227. /* Return nonzero value if X is neither zero, subnormal, Inf, nor NaN. */
  228. # define isnormal(x) (fpclassify (x) == FP_NORMAL)
  229. /* Return nonzero value if X is a NaN */
  230. extern int isnan(double x);
  231. #define isinf(x) \
  232. (sizeof (x) == sizeof (float) ? \
  233. __isinff (x) \
  234. : sizeof (x) == sizeof (double) ? \
  235. __isinf (x) : __isinfl (x))
  236. #else
  237. # define isinf(x) \
  238. (sizeof (x) == sizeof (float) ? __isinff (x) : __isinf (x))
  239. #endif
  240. #ifdef __UCLIBC_HAS_LIBM_LONG_DOUBLE__
  241. /* Return nonzero value if sign of X is negative. */
  242. extern int signbitl(long double x);
  243. /* Return nonzero value if X is not +-Inf or NaN. */
  244. extern int isfinitel(long double x);
  245. /* Return nonzero value if X is a NaN */
  246. extern int isnanl(long double x);
  247. #endif
  248. /* Some useful constants. */
  249. #if defined __USE_BSD || defined __USE_XOPEN
  250. # define M_E 2.7182818284590452354 /* e */
  251. # define M_LOG2E 1.4426950408889634074 /* log_2 e */
  252. # define M_LOG10E 0.43429448190325182765 /* log_10 e */
  253. # define M_LN2 0.69314718055994530942 /* log_e 2 */
  254. # define M_LN10 2.30258509299404568402 /* log_e 10 */
  255. # define M_PI 3.14159265358979323846 /* pi */
  256. # define M_PI_2 1.57079632679489661923 /* pi/2 */
  257. # define M_PI_4 0.78539816339744830962 /* pi/4 */
  258. # define M_1_PI 0.31830988618379067154 /* 1/pi */
  259. # define M_2_PI 0.63661977236758134308 /* 2/pi */
  260. # define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */
  261. # define M_SQRT2 1.41421356237309504880 /* sqrt(2) */
  262. # define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */
  263. #endif
  264. #ifdef __USE_GNU
  265. # define M_El M_E
  266. # define M_LOG2El M_LOG2E
  267. # define M_LOG10El M_LOG10E
  268. # define M_LN2l M_LN2
  269. # define M_LN10l M_LN10
  270. # define M_PIl M_PI
  271. # define M_PI_2l M_PI_2
  272. # define M_PI_4l M_PI_4
  273. # define M_1_PIl M_1_PI
  274. # define M_2_PIl M_2_PI
  275. # define M_2_SQRTPIl M_2_SQRTPI
  276. # define M_SQRT2l M_SQRT2
  277. # define M_SQRT1_2l M_SQRT1_2
  278. #endif
  279. #ifdef __UCLIBC_HAS_LIBM_DOUBLE__
  280. /* 7.12.4 Trigonometric functions */
  281. extern double acos(double x);
  282. extern double asin(double x);
  283. extern double atan(double x);
  284. extern double atan2(double y, double x);
  285. extern double cos(double x);
  286. extern double sin(double x);
  287. extern double tan(double x);
  288. /* 7.12.5 Hyperbolic functions */
  289. extern double acosh(double x);
  290. extern double asinh(double x);
  291. extern double atanh(double x);
  292. extern double cosh(double x);
  293. extern double sinh(double x);
  294. extern double tanh(double x);
  295. /* 7.12.6 Exponential and logarithmic functions */
  296. extern double exp(double x);
  297. extern double exp2(double x);
  298. extern double expm1(double x);
  299. extern double frexp(double value, int *exp);
  300. extern int ilogb(double x);
  301. extern double ldexp(double x, int exp);
  302. extern double log(double x);
  303. extern double log10(double x);
  304. extern double log1p(double x);
  305. extern double log2(double x);
  306. extern double logb(double x);
  307. extern double modf(double value, double *iptr);
  308. extern double scalbn(double x, int n);
  309. extern double scalbln(double x, long int n);
  310. /* 7.12.7 Power and absolute-value functions */
  311. extern double fabs(double x);
  312. extern double hypot(double x, double y);
  313. extern double pow(double x, double y);
  314. extern double sqrt(double x);
  315. /* 7.12.8 Error and gamma functions */
  316. extern double erf(double x);
  317. extern double erfc(double x);
  318. extern double lgamma(double x);
  319. extern double tgamma(double x);
  320. /* 7.12.9 Nearest integer functions */
  321. extern double ceil(double x);
  322. extern double floor(double x);
  323. extern double nearbyint(double x);
  324. extern double rint(double x);
  325. extern long int lrint(double x);
  326. extern long long int llrint(double x);
  327. extern double round(double x);
  328. extern long int lround(double x);
  329. extern long long int llround(double x);
  330. extern double trunc(double x);
  331. /* 7.12.10 Remainder functions */
  332. extern double fmod(double x, double y);
  333. extern double remainder(double x, double y);
  334. extern double remquo(double x, double y, int *quo);
  335. /* 7.12.11 Manipulation functions */
  336. extern double copysign(double x, double y);
  337. extern double nan(const char *tagp);
  338. extern double nextafter(double x, double y);
  339. /* 7.12.12 Maximum, minimum, and positive difference functions */
  340. extern double fdim(double x, double y);
  341. extern double fmax(double x, double y);
  342. extern double fmin(double x, double y);
  343. /* 7.12.13 Floating multiply-add */
  344. extern double fma(double x, double y, double z);
  345. #endif
  346. #ifdef __UCLIBC_HAS_LIBM_FLOAT__
  347. /* 7.12.4 Trigonometric functions */
  348. extern float acosf(float x);
  349. extern float asinf(float x);
  350. extern float atanf(float x);
  351. extern float atan2f(float y, float x);
  352. extern float cosf(float x);
  353. extern float sinf(float x);
  354. extern float tanf(float x);
  355. /* 7.12.5 Hyperbolic functions */
  356. extern float acoshf(float x);
  357. extern float asinhf(float x);
  358. extern float atanhf(float x);
  359. extern float coshf(float x);
  360. extern float sinhf(float x);
  361. extern float tanhf(float x);
  362. /* 7.12.6 Exponential and logarithmic functions */
  363. extern float expf(float x);
  364. extern float exp2f(float x);
  365. extern float expm1f(float x);
  366. extern float frexpf(float value, int *exp);
  367. extern int ilogbf(float x);
  368. extern float ldexpf(float x, int exp);
  369. extern float logf(float x);
  370. extern float log10f(float x);
  371. extern float log1pf(float x);
  372. extern float log2f(float x);
  373. extern float logbf(float x);
  374. extern float modff(float value, float *iptr);
  375. extern float scalbnf(float x, int n);
  376. extern float scalblnf(float x, long int n);
  377. /* 7.12.7 Power and absolute-value functions */
  378. extern float fabsf(float x);
  379. extern float hypotf(float x, float y);
  380. extern float powf(float x, float y);
  381. extern float sqrtf(float x);
  382. /* 7.12.8 Error and gamma functions */
  383. extern float erff(float x);
  384. extern float erfcf(float x);
  385. extern float lgammaf(float x);
  386. extern float tgammaf(float x);
  387. /* 7.12.9 Nearest integer functions */
  388. extern float ceilf(float x);
  389. extern float floorf(float x);
  390. extern float nearbyintf(float x);
  391. extern float rintf(float x);
  392. extern long int lrintf(float x);
  393. extern long long int llrintf(float x);
  394. extern float roundf(float x);
  395. extern long int lroundf(float x);
  396. extern long long int llroundf(float x);
  397. extern float truncf(float x);
  398. /* 7.12.10 Remainder functions */
  399. extern float fmodf(float x, float y);
  400. extern float remainderf(float x, float y);
  401. extern float remquof(float x, float y, int *quo);
  402. /* 7.12.11 Manipulation functions */
  403. extern float copysignf(float x, float y);
  404. extern float nanf(const char *tagp);
  405. extern float nextafterf(float x, float y);
  406. /* 7.12.12 Maximum, minimum, and positive difference functions */
  407. extern float fdimf(float x, float y);
  408. extern float fmaxf(float x, float y);
  409. extern float fminf(float x, float y);
  410. /* 7.12.13 Floating multiply-add */
  411. extern float fmaf(float x, float y, float z);
  412. #endif
  413. #ifdef __UCLIBC_HAS_LIBM_LONG_DOUBLE__
  414. /* 7.12.4 Trigonometric functions */
  415. extern long double acosl(long double x);
  416. extern long double asinl(long double x);
  417. extern long double atanl(long double x);
  418. extern long double atan2l(long double y, long double x);
  419. extern long double cosl(long double x);
  420. extern long double sinl(long double x);
  421. extern long double tanl(long double x);
  422. /* 7.12.5 Hyperbolic functions */
  423. extern long double acoshl(long double x);
  424. extern long double asinhl(long double x);
  425. extern long double atanhl(long double x);
  426. extern long double coshl(long double x);
  427. extern long double sinhl(long double x);
  428. extern long double tanhl(long double x);
  429. /* 7.12.6 Exponential and logarithmic functions */
  430. extern long double expl(long double x);
  431. extern long double exp2l(long double x);
  432. extern long double expm1l(long double x);
  433. extern long double frexpl(long double value, int *exp);
  434. extern int ilogbl(long double x);
  435. extern long double ldexpl(long double x, int exp);
  436. extern long double logl(long double x);
  437. extern long double log10l(long double x);
  438. extern long double log1pl(long double x);
  439. extern long double log2l(long double x);
  440. extern long double logbl(long double x);
  441. extern long double modfl(long double value, long double *iptr);
  442. extern long double scalbnl(long double x, int n);
  443. extern long double scalblnl(long double x, long int n);
  444. /* 7.12.7 Power and absolute-value functions */
  445. extern long double fabsl(long double x);
  446. extern long double hypotl(long double x, long double y);
  447. extern long double powl(long double x, long double y);
  448. extern long double sqrtl(long double x);
  449. /* 7.12.8 Error and gamma functions */
  450. extern long double erfl(long double x);
  451. extern long double erfcl(long double x);
  452. extern long double lgammal(long double x);
  453. extern long double tgammal(long double x);
  454. /* 7.12.9 Nearest integer functions */
  455. extern long double ceill(long double x);
  456. extern long double floorl(long double x);
  457. extern long double nearbyintl(long double x);
  458. extern long double rintl(long double x);
  459. extern long int lrintl(long double x);
  460. extern long long int llrintl(long double x);
  461. extern long double roundl(long double x);
  462. extern long int lroundl(long double x);
  463. extern long long int llroundl(long double x);
  464. extern long double truncl(long double x);
  465. /* 7.12.10 Remainder functions */
  466. extern long double fmodl(long double x, long double y);
  467. extern long double remainderl(long double x, long double y);
  468. extern long double remquol(long double x, long double y, int *quo);
  469. /* 7.12.11 Manipulation functions */
  470. extern long double copysignl(long double x, long double y);
  471. extern long double nanl(const char *tagp);
  472. extern long double nextafterl(long double x, long double y);
  473. extern long double nexttowardl(long double x, long double y);
  474. /* 7.12.12 Maximum, minimum, and positive difference functions */
  475. extern long double fdiml(long double x, long double y);
  476. extern long double fmaxl(long double x, long double y);
  477. extern long double fminl(long double x, long double y);
  478. /* 7.12.13 Floating multiply-add */
  479. extern long double fmal(long double x, long double y, long double z);
  480. #endif
  481. /* 7.12.14 Comparison macros */
  482. # ifndef isgreater
  483. # define isgreater(x, y) \
  484. (__extension__ \
  485. ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y); \
  486. !isunordered (__x, __y) && __x > __y; }))
  487. # endif
  488. /* Return nonzero value if X is greater than or equal to Y. */
  489. # ifndef isgreaterequal
  490. # define isgreaterequal(x, y) \
  491. (__extension__ \
  492. ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y); \
  493. !isunordered (__x, __y) && __x >= __y; }))
  494. # endif
  495. /* Return nonzero value if X is less than Y. */
  496. # ifndef isless
  497. # define isless(x, y) \
  498. (__extension__ \
  499. ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y); \
  500. !isunordered (__x, __y) && __x < __y; }))
  501. # endif
  502. /* Return nonzero value if X is less than or equal to Y. */
  503. # ifndef islessequal
  504. # define islessequal(x, y) \
  505. (__extension__ \
  506. ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y); \
  507. !isunordered (__x, __y) && __x <= __y; }))
  508. # endif
  509. /* Return nonzero value if either X is less than Y or Y is less than X. */
  510. # ifndef islessgreater
  511. # define islessgreater(x, y) \
  512. (__extension__ \
  513. ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y); \
  514. !isunordered (__x, __y) && (__x < __y || __y < __x); }))
  515. # endif
  516. /* Return nonzero value if arguments are unordered. */
  517. # ifndef isunordered
  518. # define isunordered(u, v) \
  519. (__extension__ \
  520. ({ __typeof__(u) __u = (u); __typeof__(v) __v = (v); \
  521. fpclassify (__u) == FP_NAN || fpclassify (__v) == FP_NAN; }))
  522. # endif
  523. __END_DECLS
  524. #endif /* math.h */