Rev 6099 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 6099 | Rev 6536 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | #ifndef _MATH_H_ |
1 | #ifndef _MATH_H_ |
Line 2... | Line 2... | ||
2 | 2 | ||
Line 3... | Line 3... | ||
3 | #define _MATH_H_ |
3 | #define _MATH_H_ |
- | 4 | ||
4 | 5 | #include |
|
5 | #include |
6 | #include |
Line 6... | Line 7... | ||
6 | #include |
7 | #include |
Line 134... | Line 135... | ||
134 | extern double sqrt _PARAMS((double)); |
135 | extern double sqrt _PARAMS((double)); |
135 | extern double fmod _PARAMS((double, double)); |
136 | extern double fmod _PARAMS((double, double)); |
136 | #endif /* ! defined (__math_68881) */ |
137 | #endif /* ! defined (__math_68881) */ |
137 | #endif /* ! defined (_REENT_ONLY) */ |
138 | #endif /* ! defined (_REENT_ONLY) */ |
Line 138... | Line -... | ||
138 | - | ||
139 | #if !defined(__STRICT_ANSI__) || defined(__cplusplus) || \ |
139 | |
140 | (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) |
- | |
141 | 140 | #if __ISO_C_VISIBLE >= 1999 |
|
Line 142... | Line 141... | ||
142 | /* ISO C99 types and macros. */ |
141 | /* ISO C99 types and macros. */ |
143 | 142 | ||
144 | /* FIXME: FLT_EVAL_METHOD should somehow be gotten from float.h (which is hard, |
143 | /* FIXME: FLT_EVAL_METHOD should somehow be gotten from float.h (which is hard, |
Line 203... | Line 202... | ||
203 | extern int __fpclassifyf (float x); |
202 | extern int __fpclassifyf (float x); |
204 | extern int __fpclassifyd (double x); |
203 | extern int __fpclassifyd (double x); |
205 | extern int __signbitf (float x); |
204 | extern int __signbitf (float x); |
206 | extern int __signbitd (double x); |
205 | extern int __signbitd (double x); |
Line -... | Line 206... | ||
- | 206 | ||
- | 207 | /* Note: isinf and isnan were once functions in newlib that took double |
|
- | 208 | * arguments. C99 specifies that these names are reserved for macros |
|
- | 209 | * supporting multiple floating point types. Thus, they are |
|
- | 210 | * now defined as macros. Implementations of the old functions |
|
- | 211 | * taking double arguments still exist for compatibility purposes |
|
- | 212 | * (prototypes for them are in |
|
- | 213 | ||
- | 214 | #if __GNUC_PREREQ (4, 4) |
|
- | 215 | #define fpclassify(__x) (__builtin_fpclassify (FP_NAN, FP_INFINITE, \ |
|
- | 216 | FP_NORMAL, FP_SUBNORMAL, \ |
|
- | 217 | FP_ZERO, __x)) |
|
- | 218 | #ifndef isfinite |
|
- | 219 | #define isfinite(__x) (__builtin_isfinite (__x)) |
|
- | 220 | #endif |
|
- | 221 | #ifndef isinf |
|
- | 222 | #define isinf(__x) (__builtin_isinf_sign (__x)) |
|
- | 223 | #endif |
|
- | 224 | #ifndef isnan |
|
- | 225 | #define isnan(__x) (__builtin_isnan (__x)) |
|
- | 226 | #endif |
|
- | 227 | #define isnormal(__x) (__builtin_isnormal (__x)) |
|
207 | 228 | #else |
|
208 | #define fpclassify(__x) \ |
229 | #define fpclassify(__x) \ |
209 | ((sizeof(__x) == sizeof(float)) ? __fpclassifyf(__x) : \ |
230 | ((sizeof(__x) == sizeof(float)) ? __fpclassifyf(__x) : \ |
210 | __fpclassifyd(__x)) |
- | |
211 | 231 | __fpclassifyd(__x)) |
|
212 | #ifndef isfinite |
232 | #ifndef isfinite |
213 | #define isfinite(__y) \ |
233 | #define isfinite(__y) \ |
214 | (__extension__ ({int __cy = fpclassify(__y); \ |
234 | (__extension__ ({int __cy = fpclassify(__y); \ |
215 | __cy != FP_INFINITE && __cy != FP_NAN;})) |
235 | __cy != FP_INFINITE && __cy != FP_NAN;})) |
216 | #endif |
- | |
217 | - | ||
218 | /* Note: isinf and isnan were once functions in newlib that took double |
- | |
219 | * arguments. C99 specifies that these names are reserved for macros |
- | |
220 | * supporting multiple floating point types. Thus, they are |
- | |
221 | * now defined as macros. Implementations of the old functions |
- | |
222 | * taking double arguments still exist for compatibility purposes |
- | |
223 | * (prototypes for them are in |
236 | #endif |
224 | #ifndef isinf |
237 | #ifndef isinf |
225 | #define isinf(y) (fpclassify(y) == FP_INFINITE) |
238 | #define isinf(__x) (fpclassify(__x) == FP_INFINITE) |
226 | #endif |
- | |
227 | 239 | #endif |
|
228 | #ifndef isnan |
240 | #ifndef isnan |
- | 241 | #define isnan(__x) (fpclassify(__x) == FP_NAN) |
|
- | 242 | #endif |
|
229 | #define isnan(y) (fpclassify(y) == FP_NAN) |
243 | #define isnormal(__x) (fpclassify(__x) == FP_NORMAL) |
Line -... | Line 244... | ||
- | 244 | #endif |
|
- | 245 | ||
- | 246 | #if __GNUC_PREREQ (4, 0) |
|
- | 247 | #if defined(_HAVE_LONG_DOUBLE) |
|
- | 248 | #define signbit(__x) \ |
|
- | 249 | ((sizeof(__x) == sizeof(float)) ? __builtin_signbitf(__x) : \ |
|
- | 250 | (sizeof(__x) == sizeof(double)) ? __builtin_signbit (__x) : \ |
|
- | 251 | __builtin_signbitl(__x)) |
|
- | 252 | #else |
|
230 | #endif |
253 | #define signbit(__x) \ |
- | 254 | ((sizeof(__x) == sizeof(float)) ? __builtin_signbitf(__x) : \ |
|
- | 255 | __builtin_signbit (__x)) |
|
231 | 256 | #endif |
|
232 | #define isnormal(y) (fpclassify(y) == FP_NORMAL) |
257 | #else |
233 | #define signbit(__x) \ |
258 | #define signbit(__x) \ |
- | 259 | ((sizeof(__x) == sizeof(float)) ? __signbitf(__x) : \ |
|
Line -... | Line 260... | ||
- | 260 | __signbitd(__x)) |
|
- | 261 | #endif |
|
- | 262 | ||
- | 263 | #if __GNUC_PREREQ (2, 97) |
|
- | 264 | #define isgreater(__x,__y) (__builtin_isgreater (__x, __y)) |
|
- | 265 | #define isgreaterequal(__x,__y) (__builtin_isgreaterequal (__x, __y)) |
|
- | 266 | #define isless(__x,__y) (__builtin_isless (__x, __y)) |
|
- | 267 | #define islessequal(__x,__y) (__builtin_islessequal (__x, __y)) |
|
234 | ((sizeof(__x) == sizeof(float)) ? __signbitf(__x) : \ |
268 | #define islessgreater(__x,__y) (__builtin_islessgreater (__x, __y)) |
235 | __signbitd(__x)) |
269 | #define isunordered(__x,__y) (__builtin_isunordered (__x, __y)) |
236 | 270 | #else |
|
237 | #define isgreater(x,y) \ |
271 | #define isgreater(x,y) \ |
238 | (__extension__ ({__typeof__(x) __x = (x); __typeof__(y) __y = (y); \ |
272 | (__extension__ ({__typeof__(x) __x = (x); __typeof__(y) __y = (y); \ |
Line 251... | Line 285... | ||
251 | !isunordered(__x,__y) && (__x < __y || __x > __y);})) |
285 | !isunordered(__x,__y) && (__x < __y || __x > __y);})) |
Line 252... | Line 286... | ||
252 | 286 | ||
253 | #define isunordered(a,b) \ |
287 | #define isunordered(a,b) \ |
254 | (__extension__ ({__typeof__(a) __a = (a); __typeof__(b) __b = (b); \ |
288 | (__extension__ ({__typeof__(a) __a = (a); __typeof__(b) __b = (b); \ |
- | 289 | fpclassify(__a) == FP_NAN || fpclassify(__b) == FP_NAN;})) |
|
Line 255... | Line 290... | ||
255 | fpclassify(__a) == FP_NAN || fpclassify(__b) == FP_NAN;})) |
290 | #endif |
Line 256... | Line 291... | ||
256 | 291 | ||
Line 384... | Line 419... | ||
384 | extern float erfcf _PARAMS((float)); |
419 | extern float erfcf _PARAMS((float)); |
385 | extern float log2f _PARAMS((float)); |
420 | extern float log2f _PARAMS((float)); |
386 | extern float hypotf _PARAMS((float, float)); |
421 | extern float hypotf _PARAMS((float, float)); |
387 | #endif /* ! defined (_REENT_ONLY) */ |
422 | #endif /* ! defined (_REENT_ONLY) */ |
Line -... | Line 423... | ||
- | 423 | ||
388 | 424 | /* Newlib doesn't fully support long double math functions so far. |
|
- | 425 | On platforms where long double equals double the long double functions |
|
- | 426 | simply call the double functions. On Cygwin the long double functions |
|
- | 427 | are implemented independently from newlib to be able to use optimized |
|
389 | /* On platforms where long double equals double. */ |
428 | assembler functions despite using the Microsoft x86_64 ABI. */ |
390 | #ifdef _LDBL_EQ_DBL |
429 | #if defined (_LDBL_EQ_DBL) || defined (__CYGWIN__) |
391 | /* Reentrant ANSI C functions. */ |
430 | /* Reentrant ANSI C functions. */ |
392 | #ifndef __math_68881 |
431 | #ifndef __math_68881 |
393 | extern long double atanl _PARAMS((long double)); |
432 | extern long double atanl _PARAMS((long double)); |
394 | extern long double cosl _PARAMS((long double)); |
433 | extern long double cosl _PARAMS((long double)); |
Line 455... | Line 494... | ||
455 | extern long double remainderl _PARAMS((long double, long double)); |
494 | extern long double remainderl _PARAMS((long double, long double)); |
456 | extern long double lgammal _PARAMS((long double)); |
495 | extern long double lgammal _PARAMS((long double)); |
457 | extern long double erfl _PARAMS((long double)); |
496 | extern long double erfl _PARAMS((long double)); |
458 | extern long double erfcl _PARAMS((long double)); |
497 | extern long double erfcl _PARAMS((long double)); |
459 | #endif /* ! defined (_REENT_ONLY) */ |
498 | #endif /* ! defined (_REENT_ONLY) */ |
460 | #else /* !_LDBL_EQ_DBL */ |
499 | #else /* !_LDBL_EQ_DBL && !__CYGWIN__ */ |
461 | extern long double hypotl _PARAMS((long double, long double)); |
500 | extern long double hypotl _PARAMS((long double, long double)); |
462 | extern long double sqrtl _PARAMS((long double)); |
501 | extern long double sqrtl _PARAMS((long double)); |
463 | #ifdef __i386__ |
502 | #ifdef __i386__ |
464 | /* Other long double precision functions. */ |
503 | /* Other long double precision functions. */ |
465 | extern _LONG_DOUBLE rintl _PARAMS((_LONG_DOUBLE)); |
504 | extern _LONG_DOUBLE rintl _PARAMS((_LONG_DOUBLE)); |
466 | extern long int lrintl _PARAMS((_LONG_DOUBLE)); |
505 | extern long int lrintl _PARAMS((_LONG_DOUBLE)); |
467 | extern long long int llrintl _PARAMS((_LONG_DOUBLE)); |
506 | extern long long int llrintl _PARAMS((_LONG_DOUBLE)); |
468 | #endif /* __i386__ */ |
507 | #endif /* __i386__ */ |
469 | #endif /* !_LDBL_EQ_DBL */ |
508 | #endif /* !_LDBL_EQ_DBL && !__CYGWIN__ */ |
Line 470... | Line -... | ||
470 | - | ||
471 | #endif /* !defined (__STRICT_ANSI__) || defined(__cplusplus) || (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) */ |
- | |
472 | 509 | ||
Line -... | Line 510... | ||
- | 510 | #endif /* __ISO_C_VISIBLE >= 1999 */ |
|
473 | #if !defined (__STRICT_ANSI__) || defined(__cplusplus) |
511 | |
- | 512 | #if __MISC_VISIBLE |
|
- | 513 | extern double drem _PARAMS((double, double)); |
|
474 | 514 | extern float dremf _PARAMS((float, float)); |
|
- | 515 | #ifdef __CYGWIN__ |
|
475 | extern double drem _PARAMS((double, double)); |
516 | extern float dreml _PARAMS((long double, long double)); |
476 | extern void sincos _PARAMS((double, double *, double *)); |
517 | #endif /* __CYGWIN__ */ |
- | 518 | extern double gamma_r _PARAMS((double, int *)); |
|
- | 519 | extern double lgamma_r _PARAMS((double, int *)); |
|
- | 520 | extern float gammaf_r _PARAMS((float, int *)); |
|
Line -... | Line 521... | ||
- | 521 | extern float lgammaf_r _PARAMS((float, int *)); |
|
477 | extern double gamma_r _PARAMS((double, int *)); |
522 | #endif |
478 | extern double lgamma_r _PARAMS((double, int *)); |
523 | |
479 | 524 | #if __MISC_VISIBLE || __XSI_VISIBLE |
|
480 | extern double y0 _PARAMS((double)); |
525 | extern double y0 _PARAMS((double)); |
481 | extern double y1 _PARAMS((double)); |
526 | extern double y1 _PARAMS((double)); |
482 | extern double yn _PARAMS((int, double)); |
527 | extern double yn _PARAMS((int, double)); |
- | 528 | extern double j0 _PARAMS((double)); |
|
Line 483... | Line -... | ||
483 | extern double j0 _PARAMS((double)); |
- | |
484 | extern double j1 _PARAMS((double)); |
- | |
485 | extern double jn _PARAMS((int, double)); |
529 | extern double j1 _PARAMS((double)); |
486 | - | ||
487 | extern float dremf _PARAMS((float, float)); |
- | |
488 | extern void sincosf _PARAMS((float, float *, float *)); |
530 | extern double jn _PARAMS((int, double)); |
489 | extern float gammaf_r _PARAMS((float, int *)); |
531 | #endif |
490 | extern float lgammaf_r _PARAMS((float, int *)); |
532 | |
491 | 533 | #if __MISC_VISIBLE || __XSI_VISIBLE >= 600 |
|
492 | extern float y0f _PARAMS((float)); |
534 | extern float y0f _PARAMS((float)); |
493 | extern float y1f _PARAMS((float)); |
535 | extern float y1f _PARAMS((float)); |
- | 536 | extern float ynf _PARAMS((int, float)); |
|
Line 494... | Line 537... | ||
494 | extern float ynf _PARAMS((int, float)); |
537 | extern float j0f _PARAMS((float)); |
- | 538 | extern float j1f _PARAMS((float)); |
|
- | 539 | extern float jnf _PARAMS((int, float)); |
|
- | 540 | #endif |
|
- | 541 | ||
- | 542 | /* GNU extensions */ |
|
- | 543 | #if __GNU_VISIBLE |
|
495 | extern float j0f _PARAMS((float)); |
544 | extern void sincos _PARAMS((double, double *, double *)); |
496 | extern float j1f _PARAMS((float)); |
545 | extern void sincosf _PARAMS((float, float *, float *)); |
497 | extern float jnf _PARAMS((int, float)); |
546 | #ifdef __CYGWIN__ |
498 | 547 | extern void sincosl _PARAMS((long double, long double *, long double *)); |
|
499 | /* GNU extensions */ |
548 | #endif /* __CYGWIN__ */ |
Line 507... | Line 556... | ||
507 | extern float exp10f _PARAMS((float)); |
556 | extern float exp10f _PARAMS((float)); |
508 | # endif |
557 | # endif |
509 | # ifndef pow10f |
558 | # ifndef pow10f |
510 | extern float pow10f _PARAMS((float)); |
559 | extern float pow10f _PARAMS((float)); |
511 | # endif |
560 | # endif |
- | 561 | #ifdef __CYGWIN__ |
|
- | 562 | # ifndef exp10l |
|
- | 563 | extern float exp10l _PARAMS((float)); |
|
- | 564 | # endif |
|
- | 565 | # ifndef pow10l |
|
- | 566 | extern float pow10l _PARAMS((float)); |
|
- | 567 | # endif |
|
- | 568 | #endif /* __CYGWIN__ */ |
|
- | 569 | #endif /* __GNU_VISIBLE */ |
|
Line 512... | Line -... | ||
512 | - | ||
513 | #endif /* !defined (__STRICT_ANSI__) || defined(__cplusplus) */ |
- | |
514 | 570 | ||
515 | #ifndef __STRICT_ANSI__ |
- | |
516 | 571 | #if __MISC_VISIBLE || __XSI_VISIBLE |
|
517 | /* The gamma functions use a global variable, signgam. */ |
572 | /* The gamma functions use a global variable, signgam. */ |
518 | #ifndef _REENT_ONLY |
573 | #ifndef _REENT_ONLY |
519 | #define signgam (*__signgam()) |
574 | #define signgam (*__signgam()) |
520 | extern int *__signgam _PARAMS((void)); |
575 | extern int *__signgam _PARAMS((void)); |
Line 521... | Line 576... | ||
521 | #endif /* ! defined (_REENT_ONLY) */ |
576 | #endif /* ! defined (_REENT_ONLY) */ |
- | 577 | ||
Line -... | Line 578... | ||
- | 578 | #define __signgam_r(ptr) _REENT_SIGNGAM(ptr) |
|
522 | 579 | #endif /* __MISC_VISIBLE || __XSI_VISIBLE */ |
|
523 | #define __signgam_r(ptr) _REENT_SIGNGAM(ptr) |
580 | |
524 | 581 | #if __SVID_VISIBLE |
|
525 | /* The exception structure passed to the matherr routine. */ |
582 | /* The exception structure passed to the matherr routine. */ |
526 | /* We have a problem when using C++ since `exception' is a reserved |
583 | /* We have a problem when using C++ since `exception' is a reserved |
Line 552... | Line 609... | ||
552 | #define OVERFLOW 3 |
609 | #define OVERFLOW 3 |
553 | #define UNDERFLOW 4 |
610 | #define UNDERFLOW 4 |
554 | #define TLOSS 5 |
611 | #define TLOSS 5 |
555 | #define PLOSS 6 |
612 | #define PLOSS 6 |
Line 556... | Line 613... | ||
556 | 613 | ||
Line 557... | Line 614... | ||
557 | #endif /* ! defined (__STRICT_ANSI__) */ |
614 | #endif /* __SVID_VISIBLE */ |
Line 558... | Line 615... | ||
558 | 615 | ||
Line 559... | Line 616... | ||
559 | /* Useful constants. */ |
616 | /* Useful constants. */ |
Line 560... | Line 617... | ||
560 | 617 | ||
561 | #if !defined(__STRICT_ANSI__) || ((_XOPEN_SOURCE - 0) >= 500) |
618 | #if __BSD_VISIBLE || __XSI_VISIBLE >= 500 |
Line 576... | Line 633... | ||
576 | #define M_SQRT2 1.41421356237309504880 |
633 | #define M_SQRT2 1.41421356237309504880 |
577 | #define M_SQRT1_2 0.70710678118654752440 |
634 | #define M_SQRT1_2 0.70710678118654752440 |
Line 578... | Line 635... | ||
578 | 635 | ||
Line 579... | Line 636... | ||
579 | #endif |
636 | #endif |
Line 580... | Line 637... | ||
580 | 637 | ||
581 | #ifndef __STRICT_ANSI__ |
638 | #if __BSD_VISIBLE |
582 | 639 | ||
583 | #define M_TWOPI (M_PI * 2.0) |
640 | #define M_TWOPI (M_PI * 2.0) |
Line 608... | Line 665... | ||
608 | #define _IEEE_ __fdlibm_ieee |
665 | #define _IEEE_ __fdlibm_ieee |
609 | #define _SVID_ __fdlibm_svid |
666 | #define _SVID_ __fdlibm_svid |
610 | #define _XOPEN_ __fdlibm_xopen |
667 | #define _XOPEN_ __fdlibm_xopen |
611 | #define _POSIX_ __fdlibm_posix |
668 | #define _POSIX_ __fdlibm_posix |
Line 612... | Line 669... | ||
612 | 669 | ||
Line 613... | Line 670... | ||
613 | #endif /* ! defined (__STRICT_ANSI__) */ |
670 | #endif /* __BSD_VISIBLE */ |
Line 614... | Line 671... | ||
614 | 671 | ||
615 | _END_STD_C |
672 | _END_STD_C |