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
10 * The file also includes a conditional assembly definition
11 * for the type of computer arithmetic (IEEE, DEC, Motorola
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.
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.
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.
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.
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.
46 * Configurations NANS, INFINITIES, MINUSZERO, and DENORMAL
47 * may fail on many systems. Verify that they are supposed
48 * to work on your computer.
57 #ifndef __UCLIBC_HAS_FLOATS__
60 #ifndef __UCLIBC_HAS_DOUBLE__
63 #ifndef __UCLIBC_HAS_LONG_DOUBLE__
70 /* Type of computer arithmetic */
72 /* PDP-11, Pro350, VAX:
76 /* Intel IEEE, low order words come first:
80 /* Motorola IEEE, high order words come first
81 * (Sun 680x0 workstation):
85 /* UNKnown arithmetic, invokes coefficients given in
86 * normal decimal format. Beware of range boundary
87 * problems (MACHEP, MAXLOG, etc. in const.c) and
88 * roundoff problems in pow.c:
94 /* Define if the `long double' type works. */
95 #define HAVE_LONG_DOUBLE 1
97 /* Define as the return type of signal handlers (int or void). */
98 #define RETSIGTYPE void
100 /* Define if you have the ANSI C header files. */
101 #define STDC_HEADERS 1
103 /* Define if your processor stores words with the most significant
104 byte first (like Motorola and SPARC, unlike Intel and VAX). */
105 /* #undef WORDS_BIGENDIAN */
107 /* Define if floating point words are bigendian. */
108 /* #undef FLOAT_WORDS_BIGENDIAN */
110 /* The number of bytes in a int. */
113 /* Define if you have the <string.h> header file. */
114 #define HAVE_STRING_H 1
117 /* Define this `volatile' if your compiler thinks
118 * that floating point arithmetic obeys the associative
119 * and distributive laws. It will defeat some optimizations
120 * (but probably not enough of them).
122 * #define VOLATILE volatile
126 /* For 12-byte long doubles on an i386, pad a 16-bit short 0
127 * to the end of real constants initialized by integer arrays.
131 * Otherwise, the type is 10 bytes long and XPD should be
132 * defined blank (e.g., Microsoft C).
138 /* Define to support tiny denormal numbers, else undefine. */
141 /* Define to ask for infinity support, else undefine. */
144 /* Define to ask for support of numbers that are Not-a-Number,
145 else undefine. This may automatically define INFINITIES in some files. */
148 /* Define to distinguish between -0.0 and +0.0. */
151 /* Define 1 for ANSI C atan2() function
152 and ANSI prototypes for float arguments.
153 See atan.c and clog.c. */
158 /* Constant definitions for math error conditions */
160 #define DOMAIN 1 /* argument domain error */
161 #define SING 2 /* argument singularity */
162 #define OVERFLOW 3 /* overflow range error */
163 #define UNDERFLOW 4 /* underflow range error */
164 #define TLOSS 5 /* total loss of precision */
165 #define PLOSS 6 /* partial loss of precision */
170 /* Complex numeral. */
183 #ifdef HAVE_LONG_DOUBLE
184 /* Long double complex numeral. */
194 /* Variable for error reporting. See mtherr.c. */
199 /* If you define UNK, then be sure to set BIGENDIAN properly. */
201 #if __BYTE_ORDER == __BIG_ENDIAN
203 #else /* __BYTE_ORDER == __LITTLE_ENDIAN */
209 /* Get general and ISO C 9X specific information. */
210 #include <bits/mathdef.h>
216 /* Get the architecture specific values describing the floating-point
217 evaluation. The following symbols will get defined:
219 float_t floating-point type at least as wide as `float' used
220 to evaluate `float' expressions
221 double_t floating-point type at least as wide as `double' used
222 to evaluate `double' expressions
226 0 if `float_t' is `float' and `double_t' is `double'
227 1 if `float_t' and `double_t' are `double'
228 2 if `float_t' and `double_t' are `long double'
229 else `float_t' and `double_t' are unspecified
231 INFINITY representation of the infinity value of type `float'
236 If defined it indicates that the `fma' function
237 generally executes about as fast as a multiply and an add.
238 This macro is defined only iff the `fma' function is
239 implemented directly with a hardware multiply-add instructions.
241 FP_ILOGB0 Expands to a value returned by `ilogb (0.0)'.
242 FP_ILOGBNAN Expands to a value returned by `ilogb (NAN)'.
244 DECIMAL_DIG Number of decimal digits supported by conversion between
245 decimal and all internal floating-point formats.
249 /* All floating-point numbers can be put in one of these categories. */
253 # define FP_NAN FP_NAN
255 # define FP_INFINITE FP_INFINITE
257 # define FP_ZERO FP_ZERO
259 # define FP_SUBNORMAL FP_SUBNORMAL
261 # define FP_NORMAL FP_NORMAL
264 /* Return number of classification appropriate for X. */
265 # ifdef __NO_LONG_DOUBLE_MATH
266 # define fpclassify(x) \
267 (sizeof (x) == sizeof (float) ? __fpclassifyf (x) : __fpclassify (x))
269 # define fpclassify(x) \
270 (sizeof (x) == sizeof (float) ? \
272 : sizeof (x) == sizeof (double) ? \
273 __fpclassify (x) : __fpclassifyl (x))
276 /* Return nonzero value if sign of X is negative. */
277 int signbit(double x);
278 int signbitl(long double x);
280 /* Return nonzero value if X is not +-Inf or NaN. */
281 int isfinite(double x);
282 int isfinitel(long double x);
284 /* Return nonzero value if X is neither zero, subnormal, Inf, nor NaN. */
285 # define isnormal(x) (fpclassify (x) == FP_NORMAL)
287 /* Return nonzero value if X is a NaN */
289 int isnanl(long double x);
291 /* Return nonzero value is X is positive or negative infinity. */
292 # ifdef __NO_LONG_DOUBLE_MATH
294 (sizeof (x) == sizeof (float) ? __isinff (x) : __isinf (x))
297 (sizeof (x) == sizeof (float) ? \
299 : sizeof (x) == sizeof (double) ? \
300 __isinf (x) : __isinfl (x))
305 /* Some useful constants. */
306 #if defined __USE_BSD || defined __USE_XOPEN
307 # define M_E 2.7182818284590452354 /* e */
308 # define M_LOG2E 1.4426950408889634074 /* log_2 e */
309 # define M_LOG10E 0.43429448190325182765 /* log_10 e */
310 # define M_LN2 0.69314718055994530942 /* log_e 2 */
311 # define M_LN10 2.30258509299404568402 /* log_e 10 */
312 # define M_PI 3.14159265358979323846 /* pi */
313 # define M_PI_2 1.57079632679489661923 /* pi/2 */
314 # define M_PI_4 0.78539816339744830962 /* pi/4 */
315 # define M_1_PI 0.31830988618379067154 /* 1/pi */
316 # define M_2_PI 0.63661977236758134308 /* 2/pi */
317 # define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */
318 # define M_SQRT2 1.41421356237309504880 /* sqrt(2) */
319 # define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */
323 # define M_LOG2El M_LOG2E
324 # define M_LOG10El M_LOG10E
325 # define M_LN2l M_LN2
326 # define M_LN10l M_LN10
328 # define M_PI_2l M_PI_2
329 # define M_PI_4l M_PI_4
330 # define M_1_PIl M_1_PI
331 # define M_2_PIl M_2_PI
332 # define M_2_SQRTPIl M_2_SQRTPI
333 # define M_SQRT2l M_SQRT2
334 # define M_SQRT1_2l M_SQRT1_2
340 /* 7.12.4 Trigonometric functions */
341 extern double acos(double x);
342 extern float acosf(float x);
343 extern long double acosl(long double x);
345 extern double asin(double x);
346 extern float asinf(float x);
347 extern long double asinl(long double x);
349 extern double atan(double x);
350 extern float atanf(float x);
351 extern long double atanl(long double x);
353 double atan2(double y, double x);
354 float atan2f(float y, float x);
355 long double atan2l(long double y, long double x);
357 double cos(double x);
359 long double cosl(long double x);
361 double sin(double x);
363 long double sinl(long double x);
365 double tan(double x);
367 long double tanl(long double x);
370 /* 7.12.5 Hyperbolic functions */
371 double acosh(double x);
372 float acoshf(float x);
373 long double acoshl(long double x);
375 double asinh(double x);
376 float asinhf(float x);
377 long double asinhl(long double x);
379 double atanh(double x);
380 float atanhf(float x);
381 long double atanhl(long double x);
383 double cosh(double x);
384 float coshf(float x);
385 long double coshl(long double x);
387 double sinh(double x);
388 float sinhf(float x);
389 long double sinhl(long double x);
391 double tanh(double x);
392 float tanhf(float x);
393 long double tanhl(long double x);
396 /* 7.12.6 Exponential and logarithmic functions */
397 double exp(double x);
399 long double expl(long double x);
401 double exp2(double x);
402 float exp2f(float x);
403 long double exp2l(long double x);
405 double expm1(double x);
406 float expm1f(float x);
407 long double expm1l(long double x);
409 double frexp(double value, int *exp);
410 float frexpf(float value, int *exp);
411 long double frexpl(long double value, int *exp);
415 int ilogbl(long double x);
417 double ldexp(double x, int exp);
418 float ldexpf(float x, int exp);
419 long double ldexpl(long double x, int exp);
421 double log(double x);
423 long double logl(long double x);
425 double log10(double x);
426 float log10f(float x);
427 long double log10l(long double x);
429 double log1p(double x);
430 float log1pf(float x);
431 long double log1pl(long double x);
433 double log2(double x);
434 float log2f(float x);
435 long double log2l(long double x);
437 double logb(double x);
438 float logbf(float x);
439 long double logbl(long double x);
441 double modf(double value, double *iptr);
442 float modff(float value, float *iptr);
443 long double modfl(long double value, long double *iptr);
445 double scalbn(double x, int n);
446 float scalbnf(float x, int n);
447 long double scalbnl(long double x, int n);
448 double scalbln(double x, long int n);
449 float scalblnf(float x, long int n);
450 long double scalblnl(long double x, long int n);
452 /* 7.12.7 Power and absolute-value functions */
453 double fabs(double x);
454 float fabsf(float x);
455 long double fabsl(long double x);
457 double hypot(double x, double y);
458 float hypotf(float x, float y);
459 long double hypotl(long double x, long double y);
461 double pow(double x, double y);
462 float powf(float x, float y);
463 long double powl(long double x, long double y);
465 double sqrt(double x);
466 float sqrtf(float x);
467 long double sqrtl(long double x);
469 /* 7.12.8 Error and gamma functions */
470 double erf(double x);
472 long double erfl(long double x);
474 double erfc(double x);
475 float erfcf(float x);
476 long double erfcl(long double x);
478 double lgamma(double x);
479 float lgammaf(float x);
480 long double lgammal(long double x);
482 double tgamma(double x);
483 float tgammaf(float x);
484 long double tgammal(long double x);
486 /* 7.12.9 Nearest integer functions */
487 double ceil(double x);
488 float ceilf(float x);
489 long double ceill(long double x);
491 double floor(double x);
492 float floorf(float x);
493 long double floorl(long double x);
495 double nearbyint(double x);
496 float nearbyintf(float x);
497 long double nearbyintl(long double x);
499 double rint(double x);
500 float rintf(float x);
501 long double rintl(long double x);
503 long int lrint(double x);
504 long int lrintf(float x);
505 long int lrintl(long double x);
506 long long int llrint(double x);
507 long long int llrintf(float x);
508 long long int llrintl(long double x);
510 double round(double x);
511 float roundf(float x);
512 long double roundl(long double x);
514 long int lround(double x);
515 long int lroundf(float x);
516 long int lroundl(long double x);
517 long long int llround(double x);
518 long long int llroundf(float x);
519 long long int llroundl(long double x);
521 double trunc(double x);
522 float truncf(float x);
523 long double truncl(long double x);
525 /* 7.12.10 Remainder functions */
526 double fmod(double x, double y);
527 float fmodf(float x, float y);
528 long double fmodl(long double x, long double y);
530 double remainder(double x, double y);
531 float remainderf(float x, float y);
532 long double remainderl(long double x, long double y);
534 double remquo(double x, double y, int *quo);
535 float remquof(float x, float y, int *quo);
536 long double remquol(long double x, long double y, int *quo);
538 /* 7.12.11 Manipulation functions */
539 double copysign(double x, double y);
540 float copysignf(float x, float y);
541 long double copysignl(long double x, long double y);
543 double nan(const char *tagp);
544 float nanf(const char *tagp);
545 long double nanl(const char *tagp);
547 double nextafter(double x, double y);
548 float nextafterf(float x, float y);
549 long double nextafterl(long double x, long double y);
551 double nexttoward(double x, long double y);
552 float nexttowardf(float x, long double y);
553 long double nexttowardl(long double x, long double y);
555 /* 7.12.12 Maximum, minimum, and positive difference functions */
556 double fdim(double x, double y);
557 float fdimf(float x, float y);
558 long double fdiml(long double x, long double y);
560 double fmax(double x, double y);
561 float fmaxf(float x, float y);
562 long double fmaxl(long double x, long double y);
564 double fmin(double x, double y);
565 float fminf(float x, float y);
566 long double fminl(long double x, long double y);
568 /* 7.12.13 Floating multiply-add */
569 double fma(double x, double y, double z);
570 float fmaf(float x, float y, float z);
571 long double fmal(long double x, long double y, long double z);
573 /* 7.12.14 Comparison macros */
575 # define isgreater(x, y) \
577 ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y); \
578 !isunordered (__x, __y) && __x > __y; }))
581 /* Return nonzero value if X is greater than or equal to Y. */
582 # ifndef isgreaterequal
583 # define isgreaterequal(x, y) \
585 ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y); \
586 !isunordered (__x, __y) && __x >= __y; }))
589 /* Return nonzero value if X is less than Y. */
591 # define isless(x, y) \
593 ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y); \
594 !isunordered (__x, __y) && __x < __y; }))
597 /* Return nonzero value if X is less than or equal to Y. */
599 # define islessequal(x, y) \
601 ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y); \
602 !isunordered (__x, __y) && __x <= __y; }))
605 /* Return nonzero value if either X is less than Y or Y is less than X. */
606 # ifndef islessgreater
607 # define islessgreater(x, y) \
609 ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y); \
610 !isunordered (__x, __y) && (__x < __y || __y < __x); }))
613 /* Return nonzero value if arguments are unordered. */
615 # define isunordered(u, v) \
617 ({ __typeof__(u) __u = (u); __typeof__(v) __v = (v); \
618 fpclassify (__u) == FP_NAN || fpclassify (__v) == FP_NAN; }))
622 #ifndef __UCLIBC_HAS_FLOATS__
625 #ifndef __UCLIBC_HAS_DOUBLE__
628 #ifndef __UCLIBC_HAS_LONG_DOUBLE__