OSDN Git Service

uClibc now has a math library. muahahahaha!
[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
57 #ifndef __UCLIBC_HAS_FLOATS__
58     #define float int
59 #endif
60 #ifndef __UCLIBC_HAS_DOUBLE__
61     #define double int
62 #endif
63 #ifndef __UCLIBC_HAS_LONG_DOUBLE__
64     #define long
65     #ifndef double
66     #   define double int
67     #endif
68 #endif
69
70 /* Type of computer arithmetic */
71
72 /* PDP-11, Pro350, VAX:
73  */
74 /* #define DEC 1 */
75
76 /* Intel IEEE, low order words come first:
77  */
78 /* #define IBMPC 1 */
79
80 /* Motorola IEEE, high order words come first
81  * (Sun 680x0 workstation):
82  */
83 /* #define MIEEE 1 */
84
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:
89  * (Sun SPARCstation)
90  */
91 #define UNK 1
92
93
94 /* Define if the `long double' type works.  */
95 #define HAVE_LONG_DOUBLE 1
96
97 /* Define as the return type of signal handlers (int or void).  */
98 #define RETSIGTYPE void
99
100 /* Define if you have the ANSI C header files.  */
101 #define STDC_HEADERS 1
102
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 */
106
107 /* Define if floating point words are bigendian.  */
108 /* #undef FLOAT_WORDS_BIGENDIAN */
109
110 /* The number of bytes in a int.  */
111 #define SIZEOF_INT 4
112
113 /* Define if you have the <string.h> header file.  */
114 #define HAVE_STRING_H 1
115
116
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).
121  *
122  * #define VOLATILE volatile
123  */
124 #define VOLATILE
125
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.
128  *
129  * #define XPD 0,
130  *
131  * Otherwise, the type is 10 bytes long and XPD should be
132  * defined blank (e.g., Microsoft C).
133  *
134  * #define XPD
135  */
136 #define XPD 0,
137
138 /* Define to support tiny denormal numbers, else undefine. */
139 #define DENORMAL 1
140
141 /* Define to ask for infinity support, else undefine. */
142 #define INFINITIES 1
143
144 /* Define to ask for support of numbers that are Not-a-Number,
145    else undefine.  This may automatically define INFINITIES in some files. */
146 #define NANS 1
147
148 /* Define to distinguish between -0.0 and +0.0.  */
149 #define MINUSZERO 1
150
151 /* Define 1 for ANSI C atan2() function
152    and ANSI prototypes for float arguments.
153    See atan.c and clog.c. */
154 #define ANSIC 1
155 #define ANSIPROT 1
156
157
158 /* Constant definitions for math error conditions */
159
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 */
166
167 #define EDOM            33
168 #define ERANGE          34
169
170 /* Complex numeral.  */
171 typedef struct
172         {
173         double r;
174         double i;
175         } cmplx;
176
177 typedef struct
178         {
179         float r;
180         float i;
181         } cmplxf;
182
183 #ifdef HAVE_LONG_DOUBLE
184 /* Long double complex numeral.  */
185 typedef struct
186         {
187         long double r;
188         long double i;
189         } cmplxl;
190 #endif
191
192
193
194 /* Variable for error reporting.  See mtherr.c.  */
195 extern int mtherr();
196 extern int merror;
197
198
199 /* If you define UNK, then be sure to set BIGENDIAN properly. */
200 #include <endian.h>
201 #if __BYTE_ORDER == __BIG_ENDIAN
202 #  define BIGENDIAN 1
203 #else /* __BYTE_ORDER == __LITTLE_ENDIAN */
204 #  define BIGENDIAN 0
205 #endif
206
207
208 #define __USE_ISOC9X
209 /* Get general and ISO C 9X specific information.  */
210 #include <bits/mathdef.h>
211 #undef INFINITY
212 #undef DECIMAL_DIG
213 #undef FP_ILOGB0
214 #undef FP_ILOGBNAN
215
216 /* Get the architecture specific values describing the floating-point
217    evaluation.  The following symbols will get defined:
218
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
223
224     FLT_EVAL_METHOD
225                 Defined to
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
230
231     INFINITY    representation of the infinity value of type `float'
232
233     FP_FAST_FMA
234     FP_FAST_FMAF
235     FP_FAST_FMAL
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.
240
241     FP_ILOGB0   Expands to a value returned by `ilogb (0.0)'.
242     FP_ILOGBNAN Expands to a value returned by `ilogb (NAN)'.
243
244     DECIMAL_DIG Number of decimal digits supported by conversion between
245                 decimal and all internal floating-point formats.
246
247 */
248
249 /* All floating-point numbers can be put in one of these categories.  */
250 enum
251   {
252     FP_NAN,
253 # define FP_NAN FP_NAN
254     FP_INFINITE,
255 # define FP_INFINITE FP_INFINITE
256     FP_ZERO,
257 # define FP_ZERO FP_ZERO
258     FP_SUBNORMAL,
259 # define FP_SUBNORMAL FP_SUBNORMAL
260     FP_NORMAL
261 # define FP_NORMAL FP_NORMAL
262   };
263
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))
268 # else
269 #  define fpclassify(x) \
270      (sizeof (x) == sizeof (float) ?                                          \
271         __fpclassifyf (x)                                                     \
272       : sizeof (x) == sizeof (double) ?                                       \
273         __fpclassify (x) : __fpclassifyl (x))
274 # endif
275
276 /* Return nonzero value if sign of X is negative.  */
277 int signbit(double x);
278 int signbitl(long double x);
279
280 /* Return nonzero value if X is not +-Inf or NaN.  */
281 int isfinite(double x);
282 int isfinitel(long double x);
283
284 /* Return nonzero value if X is neither zero, subnormal, Inf, nor NaN.  */
285 # define isnormal(x) (fpclassify (x) == FP_NORMAL)
286
287 /* Return nonzero value if X is a NaN */
288 int isnan(double x);
289 int isnanl(long double x);
290
291 /* Return nonzero value is X is positive or negative infinity.  */
292 # ifdef __NO_LONG_DOUBLE_MATH
293 #  define isinf(x) \
294      (sizeof (x) == sizeof (float) ? __isinff (x) : __isinf (x))
295 # else
296 #  define isinf(x) \
297      (sizeof (x) == sizeof (float) ?                                          \
298         __isinff (x)                                                          \
299       : sizeof (x) == sizeof (double) ?                                       \
300         __isinf (x) : __isinfl (x))
301 # endif
302
303
304
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) */
320 #endif
321 #ifdef __USE_GNU
322 # define M_El           M_E
323 # define M_LOG2El       M_LOG2E
324 # define M_LOG10El      M_LOG10E
325 # define M_LN2l         M_LN2
326 # define M_LN10l        M_LN10
327 # define M_PIl          M_PI
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
335 #endif
336
337
338
339
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);
344
345 extern double asin(double x);
346 extern float asinf(float x);
347 extern long double asinl(long double x);
348
349 extern double atan(double x);
350 extern float atanf(float x);
351 extern long double atanl(long double x);
352
353 double atan2(double y, double x);
354 float atan2f(float y, float x);
355 long double atan2l(long double y, long double x);
356
357 double cos(double x);
358 float cosf(float x);
359 long double cosl(long double x);
360
361 double sin(double x);
362 float sinf(float x);
363 long double sinl(long double x);
364
365 double tan(double x);
366 float tanf(float x);
367 long double tanl(long double x);
368
369
370 /* 7.12.5 Hyperbolic functions */
371 double acosh(double x);
372 float acoshf(float x);
373 long double acoshl(long double x);
374
375 double asinh(double x);
376 float asinhf(float x);
377 long double asinhl(long double x);
378
379 double atanh(double x);
380 float atanhf(float x);
381 long double atanhl(long double x);
382
383 double cosh(double x);
384 float coshf(float x);
385 long double coshl(long double x);
386
387 double sinh(double x);
388 float sinhf(float x);
389 long double sinhl(long double x);
390
391 double tanh(double x);
392 float tanhf(float x);
393 long double tanhl(long double x);
394
395
396 /* 7.12.6 Exponential and logarithmic functions */
397 double exp(double x);
398 float expf(float x);
399 long double expl(long double x);
400
401 double exp2(double x);
402 float exp2f(float x);
403 long double exp2l(long double x);
404
405 double expm1(double x);
406 float expm1f(float x);
407 long double expm1l(long double x);
408
409 double frexp(double value, int *exp);
410 float frexpf(float value, int *exp);
411 long double frexpl(long double value, int *exp);
412
413 int ilogb(double x);
414 int ilogbf(float x);
415 int ilogbl(long double x);
416
417 double ldexp(double x, int exp);
418 float ldexpf(float x, int exp);
419 long double ldexpl(long double x, int exp);
420
421 double log(double x);
422 float logf(float x);
423 long double logl(long double x);
424
425 double log10(double x);
426 float log10f(float x);
427 long double log10l(long double x);
428
429 double log1p(double x);
430 float log1pf(float x);
431 long double log1pl(long double x);
432
433 double log2(double x);
434 float log2f(float x);
435 long double log2l(long double x);
436
437 double logb(double x);
438 float logbf(float x);
439 long double logbl(long double x);
440
441 double modf(double value, double *iptr);
442 float modff(float value, float *iptr);
443 long double modfl(long double value, long double *iptr);
444
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);
451
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);
456
457 double hypot(double x, double y);
458 float hypotf(float x, float y);
459 long double hypotl(long double x, long double y);
460
461 double pow(double x, double y);
462 float powf(float x, float y);
463 long double powl(long double x, long double y);
464
465 double sqrt(double x);
466 float sqrtf(float x);
467 long double sqrtl(long double x);
468
469 /* 7.12.8 Error and gamma functions */
470 double erf(double x);
471 float erff(float x);
472 long double erfl(long double x);
473
474 double erfc(double x);
475 float erfcf(float x);
476 long double erfcl(long double x);
477
478 double lgamma(double x);
479 float lgammaf(float x);
480 long double lgammal(long double x);
481
482 double tgamma(double x);
483 float tgammaf(float x);
484 long double tgammal(long double x);
485
486 /* 7.12.9 Nearest integer functions */
487 double ceil(double x);
488 float ceilf(float x);
489 long double ceill(long double x);
490
491 double floor(double x);
492 float floorf(float x);
493 long double floorl(long double x);
494
495 double nearbyint(double x);
496 float nearbyintf(float x);
497 long double nearbyintl(long double x);
498
499 double rint(double x);
500 float rintf(float x);
501 long double rintl(long double x);
502
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);
509
510 double round(double x);
511 float roundf(float x);
512 long double roundl(long double x);
513
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);
520
521 double trunc(double x);
522 float truncf(float x);
523 long double truncl(long double x);
524
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);
529
530 double remainder(double x, double y);
531 float remainderf(float x, float y);
532 long double remainderl(long double x, long double y);
533
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);
537
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);
542
543 double nan(const char *tagp);
544 float nanf(const char *tagp);
545 long double nanl(const char *tagp);
546
547 double nextafter(double x, double y);
548 float nextafterf(float x, float y);
549 long double nextafterl(long double x, long double y);
550
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);
554
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);
559
560 double fmax(double x, double y);
561 float fmaxf(float x, float y);
562 long double fmaxl(long double x, long double y);
563
564 double fmin(double x, double y);
565 float fminf(float x, float y);
566 long double fminl(long double x, long double y);
567
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);
572
573 /* 7.12.14 Comparison macros */
574 # ifndef isgreater
575 #  define isgreater(x, y) \
576   (__extension__                                                              \
577    ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y);                       \
578       !isunordered (__x, __y) && __x > __y; }))
579 # endif
580
581 /* Return nonzero value if X is greater than or equal to Y.  */
582 # ifndef isgreaterequal
583 #  define isgreaterequal(x, y) \
584   (__extension__                                                              \
585    ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y);                       \
586       !isunordered (__x, __y) && __x >= __y; }))
587 # endif
588
589 /* Return nonzero value if X is less than Y.  */
590 # ifndef isless
591 #  define isless(x, y) \
592   (__extension__                                                              \
593    ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y);                       \
594       !isunordered (__x, __y) && __x < __y; }))
595 # endif
596
597 /* Return nonzero value if X is less than or equal to Y.  */
598 # ifndef islessequal
599 #  define islessequal(x, y) \
600   (__extension__                                                              \
601    ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y);                       \
602       !isunordered (__x, __y) && __x <= __y; }))
603 # endif
604
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) \
608   (__extension__                                                              \
609    ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y);                       \
610       !isunordered (__x, __y) && (__x < __y || __y < __x); }))
611 # endif
612
613 /* Return nonzero value if arguments are unordered.  */
614 # ifndef isunordered
615 #  define isunordered(u, v) \
616   (__extension__                                                              \
617    ({ __typeof__(u) __u = (u); __typeof__(v) __v = (v);                       \
618       fpclassify (__u) == FP_NAN || fpclassify (__v) == FP_NAN; }))
619 # endif
620
621
622 #ifndef __UCLIBC_HAS_FLOATS__
623     #undef float
624 #endif
625 #ifndef __UCLIBC_HAS_DOUBLE__
626     #undef double
627 #endif
628 #ifndef __UCLIBC_HAS_LONG_DOUBLE__
629     #undef long
630     #undef double
631 #endif
632
633
634 #endif /* math.h  */