math.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  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. #ifndef __UCLIBC_HAS_FLOATS__
  54. #define float int
  55. #endif
  56. #ifndef __UCLIBC_HAS_DOUBLE__
  57. #define double int
  58. #endif
  59. #ifndef __UCLIBC_HAS_LONG_DOUBLE__
  60. #define long
  61. #ifndef double
  62. # define double int
  63. #endif
  64. #endif
  65. /* Type of computer arithmetic */
  66. /* PDP-11, Pro350, VAX:
  67. */
  68. /* #define DEC 1 */
  69. /* Intel IEEE, low order words come first:
  70. */
  71. /* #define IBMPC 1 */
  72. /* Motorola IEEE, high order words come first
  73. * (Sun 680x0 workstation):
  74. */
  75. /* #define MIEEE 1 */
  76. /* UNKnown arithmetic, invokes coefficients given in
  77. * normal decimal format. Beware of range boundary
  78. * problems (MACHEP, MAXLOG, etc. in const.c) and
  79. * roundoff problems in pow.c:
  80. * (Sun SPARCstation)
  81. */
  82. #define UNK 1
  83. /* Define if the `long double' type works. */
  84. #define HAVE_LONG_DOUBLE 1
  85. /* Define as the return type of signal handlers (int or void). */
  86. #define RETSIGTYPE void
  87. /* Define if you have the ANSI C header files. */
  88. #define STDC_HEADERS 1
  89. /* Define if your processor stores words with the most significant
  90. byte first (like Motorola and SPARC, unlike Intel and VAX). */
  91. /* #undef WORDS_BIGENDIAN */
  92. /* Define if floating point words are bigendian. */
  93. /* #undef FLOAT_WORDS_BIGENDIAN */
  94. /* The number of bytes in a int. */
  95. #define SIZEOF_INT 4
  96. /* Define if you have the <string.h> header file. */
  97. #define HAVE_STRING_H 1
  98. /* Define this `volatile' if your compiler thinks
  99. * that floating point arithmetic obeys the associative
  100. * and distributive laws. It will defeat some optimizations
  101. * (but probably not enough of them).
  102. *
  103. * #define VOLATILE volatile
  104. */
  105. #define VOLATILE
  106. /* For 12-byte long doubles on an i386, pad a 16-bit short 0
  107. * to the end of real constants initialized by integer arrays.
  108. *
  109. * #define XPD 0,
  110. *
  111. * Otherwise, the type is 10 bytes long and XPD should be
  112. * defined blank (e.g., Microsoft C).
  113. *
  114. * #define XPD
  115. */
  116. #define XPD 0,
  117. /* Define to support tiny denormal numbers, else undefine. */
  118. #define DENORMAL 1
  119. /* Define to ask for infinity support, else undefine. */
  120. #define INFINITIES 1
  121. /* Define to ask for support of numbers that are Not-a-Number,
  122. else undefine. This may automatically define INFINITIES in some files. */
  123. #define NANS 1
  124. /* Define to distinguish between -0.0 and +0.0. */
  125. #define MINUSZERO 1
  126. /* Define 1 for ANSI C atan2() function
  127. and ANSI prototypes for float arguments.
  128. See atan.c and clog.c. */
  129. #define ANSIC 1
  130. #define ANSIPROT 1
  131. /* Constant definitions for math error conditions */
  132. #define DOMAIN 1 /* argument domain error */
  133. #define SING 2 /* argument singularity */
  134. #define OVERFLOW 3 /* overflow range error */
  135. #define UNDERFLOW 4 /* underflow range error */
  136. #define TLOSS 5 /* total loss of precision */
  137. #define PLOSS 6 /* partial loss of precision */
  138. #define EDOM 33
  139. #define ERANGE 34
  140. /* Complex numeral. */
  141. typedef struct
  142. {
  143. double r;
  144. double i;
  145. } cmplx;
  146. typedef struct
  147. {
  148. float r;
  149. float i;
  150. } cmplxf;
  151. #ifdef HAVE_LONG_DOUBLE
  152. /* Long double complex numeral. */
  153. typedef struct
  154. {
  155. long double r;
  156. long double i;
  157. } cmplxl;
  158. #endif
  159. /* Variable for error reporting. See mtherr.c. */
  160. extern int mtherr();
  161. extern int merror;
  162. /* If you define UNK, then be sure to set BIGENDIAN properly. */
  163. #include <endian.h>
  164. #if __BYTE_ORDER == __BIG_ENDIAN
  165. # define BIGENDIAN 1
  166. #else /* __BYTE_ORDER == __LITTLE_ENDIAN */
  167. # define BIGENDIAN 0
  168. #endif
  169. #define __USE_ISOC9X
  170. /* Get general and ISO C 9X specific information. */
  171. #include <bits/mathdef.h>
  172. #undef INFINITY
  173. #undef DECIMAL_DIG
  174. #undef FP_ILOGB0
  175. #undef FP_ILOGBNAN
  176. /* Get the architecture specific values describing the floating-point
  177. evaluation. The following symbols will get defined:
  178. float_t floating-point type at least as wide as `float' used
  179. to evaluate `float' expressions
  180. double_t floating-point type at least as wide as `double' used
  181. to evaluate `double' expressions
  182. FLT_EVAL_METHOD
  183. Defined to
  184. 0 if `float_t' is `float' and `double_t' is `double'
  185. 1 if `float_t' and `double_t' are `double'
  186. 2 if `float_t' and `double_t' are `long double'
  187. else `float_t' and `double_t' are unspecified
  188. INFINITY representation of the infinity value of type `float'
  189. FP_FAST_FMA
  190. FP_FAST_FMAF
  191. FP_FAST_FMAL
  192. If defined it indicates that the `fma' function
  193. generally executes about as fast as a multiply and an add.
  194. This macro is defined only iff the `fma' function is
  195. implemented directly with a hardware multiply-add instructions.
  196. FP_ILOGB0 Expands to a value returned by `ilogb (0.0)'.
  197. FP_ILOGBNAN Expands to a value returned by `ilogb (NAN)'.
  198. DECIMAL_DIG Number of decimal digits supported by conversion between
  199. decimal and all internal floating-point formats.
  200. */
  201. /* All floating-point numbers can be put in one of these categories. */
  202. enum
  203. {
  204. FP_NAN,
  205. # define FP_NAN FP_NAN
  206. FP_INFINITE,
  207. # define FP_INFINITE FP_INFINITE
  208. FP_ZERO,
  209. # define FP_ZERO FP_ZERO
  210. FP_SUBNORMAL,
  211. # define FP_SUBNORMAL FP_SUBNORMAL
  212. FP_NORMAL
  213. # define FP_NORMAL FP_NORMAL
  214. };
  215. /* Return number of classification appropriate for X. */
  216. # ifdef __NO_LONG_DOUBLE_MATH
  217. # define fpclassify(x) \
  218. (sizeof (x) == sizeof (float) ? __fpclassifyf (x) : __fpclassify (x))
  219. # else
  220. # define fpclassify(x) \
  221. (sizeof (x) == sizeof (float) ? \
  222. __fpclassifyf (x) \
  223. : sizeof (x) == sizeof (double) ? \
  224. __fpclassify (x) : __fpclassifyl (x))
  225. # endif
  226. /* Return nonzero value if sign of X is negative. */
  227. int signbit(double x);
  228. int signbitl(long double x);
  229. /* Return nonzero value if X is not +-Inf or NaN. */
  230. int isfinite(double x);
  231. int isfinitel(long double x);
  232. /* Return nonzero value if X is neither zero, subnormal, Inf, nor NaN. */
  233. # define isnormal(x) (fpclassify (x) == FP_NORMAL)
  234. /* Return nonzero value if X is a NaN */
  235. int isnan(double x);
  236. int isnanl(long double x);
  237. /* Return nonzero value is X is positive or negative infinity. */
  238. # ifdef __NO_LONG_DOUBLE_MATH
  239. # define isinf(x) \
  240. (sizeof (x) == sizeof (float) ? __isinff (x) : __isinf (x))
  241. # else
  242. # define isinf(x) \
  243. (sizeof (x) == sizeof (float) ? \
  244. __isinff (x) \
  245. : sizeof (x) == sizeof (double) ? \
  246. __isinf (x) : __isinfl (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. /* 7.12.4 Trigonometric functions */
  280. extern double acos(double x);
  281. extern float acosf(float x);
  282. extern long double acosl(long double x);
  283. extern double asin(double x);
  284. extern float asinf(float x);
  285. extern long double asinl(long double x);
  286. extern double atan(double x);
  287. extern float atanf(float x);
  288. extern long double atanl(long double x);
  289. double atan2(double y, double x);
  290. float atan2f(float y, float x);
  291. long double atan2l(long double y, long double x);
  292. double cos(double x);
  293. float cosf(float x);
  294. long double cosl(long double x);
  295. double sin(double x);
  296. float sinf(float x);
  297. long double sinl(long double x);
  298. double tan(double x);
  299. float tanf(float x);
  300. long double tanl(long double x);
  301. /* 7.12.5 Hyperbolic functions */
  302. double acosh(double x);
  303. float acoshf(float x);
  304. long double acoshl(long double x);
  305. double asinh(double x);
  306. float asinhf(float x);
  307. long double asinhl(long double x);
  308. double atanh(double x);
  309. float atanhf(float x);
  310. long double atanhl(long double x);
  311. double cosh(double x);
  312. float coshf(float x);
  313. long double coshl(long double x);
  314. double sinh(double x);
  315. float sinhf(float x);
  316. long double sinhl(long double x);
  317. double tanh(double x);
  318. float tanhf(float x);
  319. long double tanhl(long double x);
  320. /* 7.12.6 Exponential and logarithmic functions */
  321. double exp(double x);
  322. float expf(float x);
  323. long double expl(long double x);
  324. double exp2(double x);
  325. float exp2f(float x);
  326. long double exp2l(long double x);
  327. double expm1(double x);
  328. float expm1f(float x);
  329. long double expm1l(long double x);
  330. double frexp(double value, int *exp);
  331. float frexpf(float value, int *exp);
  332. long double frexpl(long double value, int *exp);
  333. int ilogb(double x);
  334. int ilogbf(float x);
  335. int ilogbl(long double x);
  336. double ldexp(double x, int exp);
  337. float ldexpf(float x, int exp);
  338. long double ldexpl(long double x, int exp);
  339. double log(double x);
  340. float logf(float x);
  341. long double logl(long double x);
  342. double log10(double x);
  343. float log10f(float x);
  344. long double log10l(long double x);
  345. double log1p(double x);
  346. float log1pf(float x);
  347. long double log1pl(long double x);
  348. double log2(double x);
  349. float log2f(float x);
  350. long double log2l(long double x);
  351. double logb(double x);
  352. float logbf(float x);
  353. long double logbl(long double x);
  354. double modf(double value, double *iptr);
  355. float modff(float value, float *iptr);
  356. long double modfl(long double value, long double *iptr);
  357. double scalbn(double x, int n);
  358. float scalbnf(float x, int n);
  359. long double scalbnl(long double x, int n);
  360. double scalbln(double x, long int n);
  361. float scalblnf(float x, long int n);
  362. long double scalblnl(long double x, long int n);
  363. /* 7.12.7 Power and absolute-value functions */
  364. double fabs(double x);
  365. float fabsf(float x);
  366. long double fabsl(long double x);
  367. double hypot(double x, double y);
  368. float hypotf(float x, float y);
  369. long double hypotl(long double x, long double y);
  370. double pow(double x, double y);
  371. float powf(float x, float y);
  372. long double powl(long double x, long double y);
  373. double sqrt(double x);
  374. float sqrtf(float x);
  375. long double sqrtl(long double x);
  376. /* 7.12.8 Error and gamma functions */
  377. double erf(double x);
  378. float erff(float x);
  379. long double erfl(long double x);
  380. double erfc(double x);
  381. float erfcf(float x);
  382. long double erfcl(long double x);
  383. double lgamma(double x);
  384. float lgammaf(float x);
  385. long double lgammal(long double x);
  386. double tgamma(double x);
  387. float tgammaf(float x);
  388. long double tgammal(long double x);
  389. /* 7.12.9 Nearest integer functions */
  390. double ceil(double x);
  391. float ceilf(float x);
  392. long double ceill(long double x);
  393. double floor(double x);
  394. float floorf(float x);
  395. long double floorl(long double x);
  396. double nearbyint(double x);
  397. float nearbyintf(float x);
  398. long double nearbyintl(long double x);
  399. double rint(double x);
  400. float rintf(float x);
  401. long double rintl(long double x);
  402. long int lrint(double x);
  403. long int lrintf(float x);
  404. long int lrintl(long double x);
  405. long long int llrint(double x);
  406. long long int llrintf(float x);
  407. long long int llrintl(long double x);
  408. double round(double x);
  409. float roundf(float x);
  410. long double roundl(long double x);
  411. long int lround(double x);
  412. long int lroundf(float x);
  413. long int lroundl(long double x);
  414. long long int llround(double x);
  415. long long int llroundf(float x);
  416. long long int llroundl(long double x);
  417. double trunc(double x);
  418. float truncf(float x);
  419. long double truncl(long double x);
  420. /* 7.12.10 Remainder functions */
  421. double fmod(double x, double y);
  422. float fmodf(float x, float y);
  423. long double fmodl(long double x, long double y);
  424. double remainder(double x, double y);
  425. float remainderf(float x, float y);
  426. long double remainderl(long double x, long double y);
  427. double remquo(double x, double y, int *quo);
  428. float remquof(float x, float y, int *quo);
  429. long double remquol(long double x, long double y, int *quo);
  430. /* 7.12.11 Manipulation functions */
  431. double copysign(double x, double y);
  432. float copysignf(float x, float y);
  433. long double copysignl(long double x, long double y);
  434. double nan(const char *tagp);
  435. float nanf(const char *tagp);
  436. long double nanl(const char *tagp);
  437. double nextafter(double x, double y);
  438. float nextafterf(float x, float y);
  439. long double nextafterl(long double x, long double y);
  440. double nexttoward(double x, long double y);
  441. float nexttowardf(float x, long double y);
  442. long double nexttowardl(long double x, long double y);
  443. /* 7.12.12 Maximum, minimum, and positive difference functions */
  444. double fdim(double x, double y);
  445. float fdimf(float x, float y);
  446. long double fdiml(long double x, long double y);
  447. double fmax(double x, double y);
  448. float fmaxf(float x, float y);
  449. long double fmaxl(long double x, long double y);
  450. double fmin(double x, double y);
  451. float fminf(float x, float y);
  452. long double fminl(long double x, long double y);
  453. /* 7.12.13 Floating multiply-add */
  454. double fma(double x, double y, double z);
  455. float fmaf(float x, float y, float z);
  456. long double fmal(long double x, long double y, long double z);
  457. /* 7.12.14 Comparison macros */
  458. # ifndef isgreater
  459. # define isgreater(x, y) \
  460. (__extension__ \
  461. ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y); \
  462. !isunordered (__x, __y) && __x > __y; }))
  463. # endif
  464. /* Return nonzero value if X is greater than or equal to Y. */
  465. # ifndef isgreaterequal
  466. # define isgreaterequal(x, y) \
  467. (__extension__ \
  468. ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y); \
  469. !isunordered (__x, __y) && __x >= __y; }))
  470. # endif
  471. /* Return nonzero value if X is less than Y. */
  472. # ifndef isless
  473. # define isless(x, y) \
  474. (__extension__ \
  475. ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y); \
  476. !isunordered (__x, __y) && __x < __y; }))
  477. # endif
  478. /* Return nonzero value if X is less than or equal to Y. */
  479. # ifndef islessequal
  480. # define islessequal(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 either X is less than Y or Y is less than X. */
  486. # ifndef islessgreater
  487. # define islessgreater(x, y) \
  488. (__extension__ \
  489. ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y); \
  490. !isunordered (__x, __y) && (__x < __y || __y < __x); }))
  491. # endif
  492. /* Return nonzero value if arguments are unordered. */
  493. # ifndef isunordered
  494. # define isunordered(u, v) \
  495. (__extension__ \
  496. ({ __typeof__(u) __u = (u); __typeof__(v) __v = (v); \
  497. fpclassify (__u) == FP_NAN || fpclassify (__v) == FP_NAN; }))
  498. # endif
  499. #ifndef __UCLIBC_HAS_FLOATS__
  500. #undef float
  501. #endif
  502. #ifndef __UCLIBC_HAS_DOUBLE__
  503. #undef double
  504. #endif
  505. #ifndef __UCLIBC_HAS_LONG_DOUBLE__
  506. #undef long
  507. #undef double
  508. #endif
  509. #endif /* math.h */