OSDN Git Service

math: remove sun copyright from libm.h
[android-x86/external-musl-libc.git] / src / internal / libm.h
1 #ifndef _LIBM_H
2 #define _LIBM_H
3
4 #include <stdint.h>
5 #include <float.h>
6 #include <math.h>
7 #include <endian.h>
8
9 #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
10 #elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 && __BYTE_ORDER == __LITTLE_ENDIAN
11 union ldshape {
12         long double f;
13         struct {
14                 uint64_t m;
15                 uint16_t se;
16         } i;
17 };
18 #elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 && __BYTE_ORDER == __BIG_ENDIAN
19 /* This is the m68k variant of 80-bit long double, and this definition only works
20  * on archs where the alignment requirement of uint64_t is <= 4. */
21 union ldshape {
22         long double f;
23         struct {
24                 uint16_t se;
25                 uint16_t pad;
26                 uint64_t m;
27         } i;
28 };
29 #elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 && __BYTE_ORDER == __LITTLE_ENDIAN
30 union ldshape {
31         long double f;
32         struct {
33                 uint64_t lo;
34                 uint32_t mid;
35                 uint16_t top;
36                 uint16_t se;
37         } i;
38         struct {
39                 uint64_t lo;
40                 uint64_t hi;
41         } i2;
42 };
43 #elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 && __BYTE_ORDER == __BIG_ENDIAN
44 union ldshape {
45         long double f;
46         struct {
47                 uint16_t se;
48                 uint16_t top;
49                 uint32_t mid;
50                 uint64_t lo;
51         } i;
52         struct {
53                 uint64_t hi;
54                 uint64_t lo;
55         } i2;
56 };
57 #else
58 #error Unsupported long double representation
59 #endif
60
61 #define FORCE_EVAL(x) do {                        \
62         if (sizeof(x) == sizeof(float)) {         \
63                 volatile float __x;               \
64                 __x = (x);                        \
65         } else if (sizeof(x) == sizeof(double)) { \
66                 volatile double __x;              \
67                 __x = (x);                        \
68         } else {                                  \
69                 volatile long double __x;         \
70                 __x = (x);                        \
71         }                                         \
72 } while(0)
73
74 #define asuint(f) ((union{float _f; uint32_t _i;}){f})._i
75 #define asfloat(i) ((union{uint32_t _i; float _f;}){i})._f
76 #define asuint64(f) ((union{double _f; uint64_t _i;}){f})._i
77 #define asdouble(i) ((union{uint64_t _i; double _f;}){i})._f
78
79 #define EXTRACT_WORDS(hi,lo,d)                    \
80 do {                                              \
81   uint64_t __u = asuint64(d);                     \
82   (hi) = __u >> 32;                               \
83   (lo) = (uint32_t)__u;                           \
84 } while (0)
85
86 #define GET_HIGH_WORD(hi,d)                       \
87 do {                                              \
88   (hi) = asuint64(d) >> 32;                       \
89 } while (0)
90
91 #define GET_LOW_WORD(lo,d)                        \
92 do {                                              \
93   (lo) = (uint32_t)asuint64(d);                   \
94 } while (0)
95
96 #define INSERT_WORDS(d,hi,lo)                     \
97 do {                                              \
98   (d) = asdouble(((uint64_t)(hi)<<32) | (uint32_t)(lo)); \
99 } while (0)
100
101 #define SET_HIGH_WORD(d,hi)                       \
102   INSERT_WORDS(d, hi, (uint32_t)asuint64(d))
103
104 #define SET_LOW_WORD(d,lo)                        \
105   INSERT_WORDS(d, asuint64(d)>>32, lo)
106
107 #define GET_FLOAT_WORD(w,d)                       \
108 do {                                              \
109   (w) = asuint(d);                                \
110 } while (0)
111
112 #define SET_FLOAT_WORD(d,w)                       \
113 do {                                              \
114   (d) = asfloat(w);                               \
115 } while (0)
116
117 hidden int    __rem_pio2_large(double*,double*,int,int,int);
118
119 hidden int    __rem_pio2(double,double*);
120 hidden double __sin(double,double,int);
121 hidden double __cos(double,double);
122 hidden double __tan(double,double,int);
123 hidden double __expo2(double);
124
125 hidden int    __rem_pio2f(float,double*);
126 hidden float  __sindf(double);
127 hidden float  __cosdf(double);
128 hidden float  __tandf(double,int);
129 hidden float  __expo2f(float);
130
131 hidden int __rem_pio2l(long double, long double *);
132 hidden long double __sinl(long double, long double, int);
133 hidden long double __cosl(long double, long double);
134 hidden long double __tanl(long double, long double, int);
135
136 hidden long double __polevll(long double, const long double *, int);
137 hidden long double __p1evll(long double, const long double *, int);
138
139 extern int __signgam;
140 hidden double __lgamma_r(double, int *);
141 hidden float __lgammaf_r(float, int *);
142
143 #endif