Add new pow implementation
[glibc.git] / sysdeps / generic / math_private.h
blobd91b9295627c8b647c56a264fadc010aa4bb279e
1 /*
2 * ====================================================
3 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
5 * Developed at SunPro, a Sun Microsystems, Inc. business.
6 * Permission to use, copy, modify, and distribute this
7 * software is freely granted, provided that this notice
8 * is preserved.
9 * ====================================================
13 * from: @(#)fdlibm.h 5.1 93/09/24
16 #ifndef _MATH_PRIVATE_H_
17 #define _MATH_PRIVATE_H_
19 #include <endian.h>
20 #include <stdbool.h>
21 #include <stdint.h>
22 #include <sys/types.h>
24 /* Gather machine dependent _Floatn support. */
25 #include <bits/floatn.h>
27 /* The original fdlibm code used statements like:
28 n0 = ((*(int*)&one)>>29)^1; * index of high word *
29 ix0 = *(n0+(int*)&x); * high word of x *
30 ix1 = *((1-n0)+(int*)&x); * low word of x *
31 to dig two 32 bit words out of the 64 bit IEEE floating point
32 value. That is non-ANSI, and, moreover, the gcc instruction
33 scheduler gets it wrong. We instead use the following macros.
34 Unlike the original code, we determine the endianness at compile
35 time, not at run time; I don't see much benefit to selecting
36 endianness at run time. */
38 /* A union which permits us to convert between a double and two 32 bit
39 ints. */
41 #if __FLOAT_WORD_ORDER == __BIG_ENDIAN
43 typedef union
45 double value;
46 struct
48 uint32_t msw;
49 uint32_t lsw;
50 } parts;
51 uint64_t word;
52 } ieee_double_shape_type;
54 #endif
56 #if __FLOAT_WORD_ORDER == __LITTLE_ENDIAN
58 typedef union
60 double value;
61 struct
63 uint32_t lsw;
64 uint32_t msw;
65 } parts;
66 uint64_t word;
67 } ieee_double_shape_type;
69 #endif
71 /* Get two 32 bit ints from a double. */
73 #define EXTRACT_WORDS(ix0,ix1,d) \
74 do { \
75 ieee_double_shape_type ew_u; \
76 ew_u.value = (d); \
77 (ix0) = ew_u.parts.msw; \
78 (ix1) = ew_u.parts.lsw; \
79 } while (0)
81 /* Get the more significant 32 bit int from a double. */
83 #ifndef GET_HIGH_WORD
84 # define GET_HIGH_WORD(i,d) \
85 do { \
86 ieee_double_shape_type gh_u; \
87 gh_u.value = (d); \
88 (i) = gh_u.parts.msw; \
89 } while (0)
90 #endif
92 /* Get the less significant 32 bit int from a double. */
94 #ifndef GET_LOW_WORD
95 # define GET_LOW_WORD(i,d) \
96 do { \
97 ieee_double_shape_type gl_u; \
98 gl_u.value = (d); \
99 (i) = gl_u.parts.lsw; \
100 } while (0)
101 #endif
103 /* Get all in one, efficient on 64-bit machines. */
104 #ifndef EXTRACT_WORDS64
105 # define EXTRACT_WORDS64(i,d) \
106 do { \
107 ieee_double_shape_type gh_u; \
108 gh_u.value = (d); \
109 (i) = gh_u.word; \
110 } while (0)
111 #endif
113 /* Set a double from two 32 bit ints. */
114 #ifndef INSERT_WORDS
115 # define INSERT_WORDS(d,ix0,ix1) \
116 do { \
117 ieee_double_shape_type iw_u; \
118 iw_u.parts.msw = (ix0); \
119 iw_u.parts.lsw = (ix1); \
120 (d) = iw_u.value; \
121 } while (0)
122 #endif
124 /* Get all in one, efficient on 64-bit machines. */
125 #ifndef INSERT_WORDS64
126 # define INSERT_WORDS64(d,i) \
127 do { \
128 ieee_double_shape_type iw_u; \
129 iw_u.word = (i); \
130 (d) = iw_u.value; \
131 } while (0)
132 #endif
134 /* Set the more significant 32 bits of a double from an int. */
135 #ifndef SET_HIGH_WORD
136 #define SET_HIGH_WORD(d,v) \
137 do { \
138 ieee_double_shape_type sh_u; \
139 sh_u.value = (d); \
140 sh_u.parts.msw = (v); \
141 (d) = sh_u.value; \
142 } while (0)
143 #endif
145 /* Set the less significant 32 bits of a double from an int. */
146 #ifndef SET_LOW_WORD
147 # define SET_LOW_WORD(d,v) \
148 do { \
149 ieee_double_shape_type sl_u; \
150 sl_u.value = (d); \
151 sl_u.parts.lsw = (v); \
152 (d) = sl_u.value; \
153 } while (0)
154 #endif
156 /* A union which permits us to convert between a float and a 32 bit
157 int. */
159 typedef union
161 float value;
162 uint32_t word;
163 } ieee_float_shape_type;
165 /* Get a 32 bit int from a float. */
166 #ifndef GET_FLOAT_WORD
167 # define GET_FLOAT_WORD(i,d) \
168 do { \
169 ieee_float_shape_type gf_u; \
170 gf_u.value = (d); \
171 (i) = gf_u.word; \
172 } while (0)
173 #endif
175 /* Set a float from a 32 bit int. */
176 #ifndef SET_FLOAT_WORD
177 # define SET_FLOAT_WORD(d,i) \
178 do { \
179 ieee_float_shape_type sf_u; \
180 sf_u.word = (i); \
181 (d) = sf_u.value; \
182 } while (0)
183 #endif
185 /* We need to guarantee an expansion of name when building
186 ldbl-128 files as another type (e.g _Float128). */
187 #define mathx_hidden_def(name) hidden_def(name)
189 /* Get long double macros from a separate header. */
190 #include <math_ldbl.h>
192 /* Include function declarations for each floating-point. */
193 #define _Mdouble_ double
194 #define _MSUF_
195 #include <math_private_calls.h>
196 #undef _MSUF_
197 #undef _Mdouble_
199 #define _Mdouble_ float
200 #define _MSUF_ f
201 #define __MATH_DECLARING_FLOAT
202 #include <math_private_calls.h>
203 #undef __MATH_DECLARING_FLOAT
204 #undef _MSUF_
205 #undef _Mdouble_
207 #define _Mdouble_ long double
208 #define _MSUF_ l
209 #define __MATH_DECLARING_LONG_DOUBLE
210 #include <math_private_calls.h>
211 #undef __MATH_DECLARING_LONG_DOUBLE
212 #undef _MSUF_
213 #undef _Mdouble_
215 #if __HAVE_DISTINCT_FLOAT128
216 # define _Mdouble_ _Float128
217 # define _MSUF_ f128
218 # define __MATH_DECLARING_FLOATN
219 # include <math_private_calls.h>
220 # undef __MATH_DECLARING_FLOATN
221 # undef _MSUF_
222 # undef _Mdouble_
223 #endif
227 /* Prototypes for functions of the IBM Accurate Mathematical Library. */
228 extern double __sin (double __x);
229 extern double __cos (double __x);
230 extern int __branred (double __x, double *__a, double *__aa);
231 extern void __doasin (double __x, double __dx, double __v[]);
232 extern void __dubsin (double __x, double __dx, double __v[]);
233 extern void __dubcos (double __x, double __dx, double __v[]);
234 extern double __sin32 (double __x, double __res, double __res1);
235 extern double __cos32 (double __x, double __res, double __res1);
236 extern double __mpsin (double __x, double __dx, bool __range_reduce);
237 extern double __mpcos (double __x, double __dx, bool __range_reduce);
238 extern void __docos (double __x, double __dx, double __v[]);
240 #endif /* _MATH_PRIVATE_H_ */