| #ifndef _LIBM_H |
| #define _LIBM_H |
| |
| #include <stdint.h> |
| #include <float.h> |
| #include <math.h> |
| #include <endian.h> |
| |
| #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 |
| #elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 && __BYTE_ORDER == __LITTLE_ENDIAN |
| union ldshape { |
| long double f; |
| struct { |
| uint64_t m; |
| uint16_t se; |
| } i; |
| }; |
| #elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 && __BYTE_ORDER == __BIG_ENDIAN |
| /* This is the m68k variant of 80-bit long double, and this definition only works |
| * on archs where the alignment requirement of uint64_t is <= 4. */ |
| union ldshape { |
| long double f; |
| struct { |
| uint16_t se; |
| uint16_t pad; |
| uint64_t m; |
| } i; |
| }; |
| #elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 && __BYTE_ORDER == __LITTLE_ENDIAN |
| union ldshape { |
| long double f; |
| struct { |
| uint64_t lo; |
| uint32_t mid; |
| uint16_t top; |
| uint16_t se; |
| } i; |
| struct { |
| uint64_t lo; |
| uint64_t hi; |
| } i2; |
| }; |
| #elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 && __BYTE_ORDER == __BIG_ENDIAN |
| union ldshape { |
| long double f; |
| struct { |
| uint16_t se; |
| uint16_t top; |
| uint32_t mid; |
| uint64_t lo; |
| } i; |
| struct { |
| uint64_t hi; |
| uint64_t lo; |
| } i2; |
| }; |
| #else |
| #error Unsupported long double representation |
| #endif |
| |
| #define FORCE_EVAL(x) do { \ |
| if (sizeof(x) == sizeof(float)) { \ |
| volatile float __x; \ |
| __x = (x); \ |
| } else if (sizeof(x) == sizeof(double)) { \ |
| volatile double __x; \ |
| __x = (x); \ |
| } else { \ |
| volatile long double __x; \ |
| __x = (x); \ |
| } \ |
| } while(0) |
| |
| #define asuint(f) ((union{float _f; uint32_t _i;}){f})._i |
| #define asfloat(i) ((union{uint32_t _i; float _f;}){i})._f |
| #define asuint64(f) ((union{double _f; uint64_t _i;}){f})._i |
| #define asdouble(i) ((union{uint64_t _i; double _f;}){i})._f |
| |
| #define EXTRACT_WORDS(hi,lo,d) \ |
| do { \ |
| uint64_t __u = asuint64(d); \ |
| (hi) = __u >> 32; \ |
| (lo) = (uint32_t)__u; \ |
| } while (0) |
| |
| #define GET_HIGH_WORD(hi,d) \ |
| do { \ |
| (hi) = asuint64(d) >> 32; \ |
| } while (0) |
| |
| #define GET_LOW_WORD(lo,d) \ |
| do { \ |
| (lo) = (uint32_t)asuint64(d); \ |
| } while (0) |
| |
| #define INSERT_WORDS(d,hi,lo) \ |
| do { \ |
| (d) = asdouble(((uint64_t)(hi)<<32) | (uint32_t)(lo)); \ |
| } while (0) |
| |
| #define SET_HIGH_WORD(d,hi) \ |
| INSERT_WORDS(d, hi, (uint32_t)asuint64(d)) |
| |
| #define SET_LOW_WORD(d,lo) \ |
| INSERT_WORDS(d, asuint64(d)>>32, lo) |
| |
| #define GET_FLOAT_WORD(w,d) \ |
| do { \ |
| (w) = asuint(d); \ |
| } while (0) |
| |
| #define SET_FLOAT_WORD(d,w) \ |
| do { \ |
| (d) = asfloat(w); \ |
| } while (0) |
| |
| hidden int __rem_pio2_large(double*,double*,int,int,int); |
| |
| hidden int __rem_pio2(double,double*); |
| hidden double __sin(double,double,int); |
| hidden double __cos(double,double); |
| hidden double __tan(double,double,int); |
| hidden double __expo2(double); |
| |
| hidden int __rem_pio2f(float,double*); |
| hidden float __sindf(double); |
| hidden float __cosdf(double); |
| hidden float __tandf(double,int); |
| hidden float __expo2f(float); |
| |
| hidden int __rem_pio2l(long double, long double *); |
| hidden long double __sinl(long double, long double, int); |
| hidden long double __cosl(long double, long double); |
| hidden long double __tanl(long double, long double, int); |
| |
| hidden long double __polevll(long double, const long double *, int); |
| hidden long double __p1evll(long double, const long double *, int); |
| |
| extern int __signgam; |
| hidden double __lgamma_r(double, int *); |
| hidden float __lgammaf_r(float, int *); |
| |
| #endif |