1 | /* origin: FreeBSD /usr/src/lib/msun/src/math_private.h */
|
---|
2 | /*
|
---|
3 | * ====================================================
|
---|
4 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
|
---|
5 | *
|
---|
6 | * Developed at SunPro, a Sun Microsystems, Inc. business.
|
---|
7 | * Permission to use, copy, modify, and distribute this
|
---|
8 | * software is freely granted, provided that this notice
|
---|
9 | * is preserved.
|
---|
10 | * ====================================================
|
---|
11 | */
|
---|
12 |
|
---|
13 | #ifndef _LIBM_H
|
---|
14 | #define _LIBM_H
|
---|
15 |
|
---|
16 | #include <stdint.h>
|
---|
17 | #include <float.h>
|
---|
18 | #include <math.h>
|
---|
19 | #include <complex.h>
|
---|
20 | #include <endian.h>
|
---|
21 |
|
---|
22 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
|
---|
23 | #elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 && __BYTE_ORDER == __LITTLE_ENDIAN
|
---|
24 | union ldshape {
|
---|
25 | long double f;
|
---|
26 | struct {
|
---|
27 | uint64_t m;
|
---|
28 | uint16_t se;
|
---|
29 | } i;
|
---|
30 | };
|
---|
31 | #elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 && __BYTE_ORDER == __LITTLE_ENDIAN
|
---|
32 | union ldshape {
|
---|
33 | long double f;
|
---|
34 | struct {
|
---|
35 | uint64_t lo;
|
---|
36 | uint32_t mid;
|
---|
37 | uint16_t top;
|
---|
38 | uint16_t se;
|
---|
39 | } i;
|
---|
40 | struct {
|
---|
41 | uint64_t lo;
|
---|
42 | uint64_t hi;
|
---|
43 | } i2;
|
---|
44 | };
|
---|
45 | #elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 && __BYTE_ORDER == __BIG_ENDIAN
|
---|
46 | union ldshape {
|
---|
47 | long double f;
|
---|
48 | struct {
|
---|
49 | uint16_t se;
|
---|
50 | uint16_t top;
|
---|
51 | uint32_t mid;
|
---|
52 | uint64_t lo;
|
---|
53 | } i;
|
---|
54 | struct {
|
---|
55 | uint64_t hi;
|
---|
56 | uint64_t lo;
|
---|
57 | } i2;
|
---|
58 | };
|
---|
59 | #else
|
---|
60 | #error Unsupported long double representation
|
---|
61 | #endif
|
---|
62 |
|
---|
63 | #define FORCE_EVAL(x) do { \
|
---|
64 | if (sizeof(x) == sizeof(float)) { \
|
---|
65 | volatile float __x; \
|
---|
66 | __x = (x); \
|
---|
67 | } else if (sizeof(x) == sizeof(double)) { \
|
---|
68 | volatile double __x; \
|
---|
69 | __x = (x); \
|
---|
70 | } else { \
|
---|
71 | volatile long double __x; \
|
---|
72 | __x = (x); \
|
---|
73 | } \
|
---|
74 | } while(0)
|
---|
75 |
|
---|
76 | /* Get two 32 bit ints from a double. */
|
---|
77 | #define EXTRACT_WORDS(hi,lo,d) \
|
---|
78 | do { \
|
---|
79 | union {double f; uint64_t i;} __u; \
|
---|
80 | __u.f = (d); \
|
---|
81 | (hi) = __u.i >> 32; \
|
---|
82 | (lo) = (uint32_t)__u.i; \
|
---|
83 | } while (0)
|
---|
84 |
|
---|
85 | /* Get the more significant 32 bit int from a double. */
|
---|
86 | #define GET_HIGH_WORD(hi,d) \
|
---|
87 | do { \
|
---|
88 | union {double f; uint64_t i;} __u; \
|
---|
89 | __u.f = (d); \
|
---|
90 | (hi) = __u.i >> 32; \
|
---|
91 | } while (0)
|
---|
92 |
|
---|
93 | /* Get the less significant 32 bit int from a double. */
|
---|
94 | #define GET_LOW_WORD(lo,d) \
|
---|
95 | do { \
|
---|
96 | union {double f; uint64_t i;} __u; \
|
---|
97 | __u.f = (d); \
|
---|
98 | (lo) = (uint32_t)__u.i; \
|
---|
99 | } while (0)
|
---|
100 |
|
---|
101 | /* Set a double from two 32 bit ints. */
|
---|
102 | #define INSERT_WORDS(d,hi,lo) \
|
---|
103 | do { \
|
---|
104 | union {double f; uint64_t i;} __u; \
|
---|
105 | __u.i = ((uint64_t)(hi)<<32) | (uint32_t)(lo); \
|
---|
106 | (d) = __u.f; \
|
---|
107 | } while (0)
|
---|
108 |
|
---|
109 | /* Set the more significant 32 bits of a double from an int. */
|
---|
110 | #define SET_HIGH_WORD(d,hi) \
|
---|
111 | do { \
|
---|
112 | union {double f; uint64_t i;} __u; \
|
---|
113 | __u.f = (d); \
|
---|
114 | __u.i &= 0xffffffff; \
|
---|
115 | __u.i |= (uint64_t)(hi) << 32; \
|
---|
116 | (d) = __u.f; \
|
---|
117 | } while (0)
|
---|
118 |
|
---|
119 | /* Set the less significant 32 bits of a double from an int. */
|
---|
120 | #define SET_LOW_WORD(d,lo) \
|
---|
121 | do { \
|
---|
122 | union {double f; uint64_t i;} __u; \
|
---|
123 | __u.f = (d); \
|
---|
124 | __u.i &= 0xffffffff00000000ull; \
|
---|
125 | __u.i |= (uint32_t)(lo); \
|
---|
126 | (d) = __u.f; \
|
---|
127 | } while (0)
|
---|
128 |
|
---|
129 | /* Get a 32 bit int from a float. */
|
---|
130 | #define GET_FLOAT_WORD(w,d) \
|
---|
131 | do { \
|
---|
132 | union {float f; uint32_t i;} __u; \
|
---|
133 | __u.f = (d); \
|
---|
134 | (w) = __u.i; \
|
---|
135 | } while (0)
|
---|
136 |
|
---|
137 | /* Set a float from a 32 bit int. */
|
---|
138 | #define SET_FLOAT_WORD(d,w) \
|
---|
139 | do { \
|
---|
140 | union {float f; uint32_t i;} __u; \
|
---|
141 | __u.i = (w); \
|
---|
142 | (d) = __u.f; \
|
---|
143 | } while (0)
|
---|
144 |
|
---|
145 | #undef __CMPLX
|
---|
146 | #undef CMPLX
|
---|
147 | #undef CMPLXF
|
---|
148 | #undef CMPLXL
|
---|
149 |
|
---|
150 | #define __CMPLX(x, y, t) \
|
---|
151 | ((union { _Complex t __z; t __xy[2]; }){.__xy = {(x),(y)}}.__z)
|
---|
152 |
|
---|
153 | #define CMPLX(x, y) __CMPLX(x, y, double)
|
---|
154 | #define CMPLXF(x, y) __CMPLX(x, y, float)
|
---|
155 | #define CMPLXL(x, y) __CMPLX(x, y, long double)
|
---|
156 |
|
---|
157 | /* fdlibm kernel functions */
|
---|
158 |
|
---|
159 | int __rem_pio2_large(double*,double*,int,int,int);
|
---|
160 |
|
---|
161 | int __rem_pio2(double,double*);
|
---|
162 | double __sin(double,double,int);
|
---|
163 | double __cos(double,double);
|
---|
164 | double __tan(double,double,int);
|
---|
165 | double __expo2(double);
|
---|
166 | double complex __ldexp_cexp(double complex,int);
|
---|
167 |
|
---|
168 | int __rem_pio2f(float,double*);
|
---|
169 | float __sindf(double);
|
---|
170 | float __cosdf(double);
|
---|
171 | float __tandf(double,int);
|
---|
172 | float __expo2f(float);
|
---|
173 | float complex __ldexp_cexpf(float complex,int);
|
---|
174 |
|
---|
175 | int __rem_pio2l(long double, long double *);
|
---|
176 | long double __sinl(long double, long double, int);
|
---|
177 | long double __cosl(long double, long double);
|
---|
178 | long double __tanl(long double, long double, int);
|
---|
179 |
|
---|
180 | /* polynomial evaluation */
|
---|
181 | long double __polevll(long double, const long double *, int);
|
---|
182 | long double __p1evll(long double, const long double *, int);
|
---|
183 |
|
---|
184 | #endif
|
---|