OSDN Git Service

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