x11gfx.hidd: support 32 bit modes
[AROS.git] / compiler / stdc / math / math_private.h
blob50ce63c8d8451f8ee4d78e1cecc8acd2e84e1447
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
14 * $FreeBSD: src/lib/msun/src/math_private.h,v 1.20 2005/11/28 04:58:57 bde Exp $
17 #ifndef _MATH_PRIVATE_H_
18 #define _MATH_PRIVATE_H_
20 #include <aros/system.h>
21 #include <stdint.h>
24 * The original fdlibm code used statements like:
25 * n0 = ((*(int*)&one)>>29)^1; * index of high word *
26 * ix0 = *(n0+(int*)&x); * high word of x *
27 * ix1 = *((1-n0)+(int*)&x); * low word of x *
28 * to dig two 32 bit words out of the 64 bit IEEE floating point
29 * value. That is non-ANSI, and, moreover, the gcc instruction
30 * scheduler gets it wrong. We instead use the following macros.
31 * Unlike the original code, we determine the endianness at compile
32 * time, not at run time; I don't see much benefit to selecting
33 * endianness at run time.
37 * A union which permits us to convert between a double and two 32 bit
38 * ints.
41 #if AROS_BIG_ENDIAN
43 typedef union
45 double value;
46 struct
48 uint32_t msw;
49 uint32_t lsw;
50 } parts;
51 } ieee_double_shape_type;
53 #endif
55 #if !AROS_BIG_ENDIAN
57 typedef union
59 double value;
60 struct
62 uint32_t lsw;
63 uint32_t msw;
64 } parts;
65 } ieee_double_shape_type;
67 #endif
69 /* Get two 32 bit ints from a double. */
71 #define EXTRACT_WORDS(ix0,ix1,d) \
72 do { \
73 ieee_double_shape_type ew_u; \
74 ew_u.value = (d); \
75 (ix0) = ew_u.parts.msw; \
76 (ix1) = ew_u.parts.lsw; \
77 } while (0)
79 /* Get the more significant 32 bit int from a double. */
81 #define GET_HIGH_WORD(i,d) \
82 do { \
83 ieee_double_shape_type gh_u; \
84 gh_u.value = (d); \
85 (i) = gh_u.parts.msw; \
86 } while (0)
88 /* Get the less significant 32 bit int from a double. */
90 #define GET_LOW_WORD(i,d) \
91 do { \
92 ieee_double_shape_type gl_u; \
93 gl_u.value = (d); \
94 (i) = gl_u.parts.lsw; \
95 } while (0)
97 /* Set a double from two 32 bit ints. */
99 #define INSERT_WORDS(d,ix0,ix1) \
100 do { \
101 ieee_double_shape_type iw_u; \
102 iw_u.parts.msw = (ix0); \
103 iw_u.parts.lsw = (ix1); \
104 (d) = iw_u.value; \
105 } while (0)
107 /* Set the more significant 32 bits of a double from an int. */
109 #define SET_HIGH_WORD(d,v) \
110 do { \
111 ieee_double_shape_type sh_u; \
112 sh_u.value = (d); \
113 sh_u.parts.msw = (v); \
114 (d) = sh_u.value; \
115 } while (0)
117 /* Set the less significant 32 bits of a double from an int. */
119 #define SET_LOW_WORD(d,v) \
120 do { \
121 ieee_double_shape_type sl_u; \
122 sl_u.value = (d); \
123 sl_u.parts.lsw = (v); \
124 (d) = sl_u.value; \
125 } while (0)
128 * A union which permits us to convert between a float and a 32 bit
129 * int.
132 typedef union
134 float value;
135 /* FIXME: Assumes 32 bit int. */
136 unsigned int word;
137 } ieee_float_shape_type;
139 /* Get a 32 bit int from a float. */
141 #define GET_FLOAT_WORD(i,d) \
142 do { \
143 ieee_float_shape_type gf_u; \
144 gf_u.value = (d); \
145 (i) = gf_u.word; \
146 } while (0)
148 /* Set a float from a 32 bit int. */
150 #define SET_FLOAT_WORD(d,i) \
151 do { \
152 ieee_float_shape_type sf_u; \
153 sf_u.word = (i); \
154 (d) = sf_u.value; \
155 } while (0)
157 #ifdef _COMPLEX_H
159 * Inline functions that can be used to construct complex values.
161 * The C99 standard intends x+I*y to be used for this, but x+I*y is
162 * currently unusable in general since gcc introduces many overflow,
163 * underflow, sign and efficiency bugs by rewriting I*y as
164 * (0.0+I)*(y+0.0*I) and laboriously computing the full complex product.
165 * In particular, I*Inf is corrupted to NaN+I*Inf, and I*-0 is corrupted
166 * to -0.0+I*0.0.
168 static __inline float complex
169 cpackf(float x, float y)
171 float complex z;
173 __real__ z = x;
174 __imag__ z = y;
175 return (z);
178 static __inline double complex
179 cpack(double x, double y)
181 double complex z;
183 __real__ z = x;
184 __imag__ z = y;
185 return (z);
188 static __inline long double complex
189 cpackl(long double x, long double y)
191 long double complex z;
193 __real__ z = x;
194 __imag__ z = y;
195 return (z);
197 #endif /* _COMPLEX_H */
200 * ieee style elementary functions
202 * We rename functions here to improve other sources' diffability
203 * against fdlibm.
205 #define __ieee754_sqrt sqrt
206 #define __ieee754_acos acos
207 #define __ieee754_acosh acosh
208 #define __ieee754_log log
209 #define __ieee754_atanh atanh
210 #define __ieee754_asin asin
211 #define __ieee754_atan2 atan2
212 #define __ieee754_exp exp
213 #define __ieee754_cosh cosh
214 #define __ieee754_fmod fmod
215 #define __ieee754_pow pow
216 #define __ieee754_lgamma lgamma
217 #define __ieee754_gamma gamma
218 #define __ieee754_lgamma_r lgamma_r
219 #define __ieee754_gamma_r gamma_r
220 #define __ieee754_log2 log2
221 #define __ieee754_log10 log10
222 #define __ieee754_sinh sinh
223 #define __ieee754_hypot hypot
224 #define __ieee754_j0 j0
225 #define __ieee754_j1 j1
226 #define __ieee754_y0 y0
227 #define __ieee754_y1 y1
228 #define __ieee754_jn jn
229 #define __ieee754_yn yn
230 #define __ieee754_remainder remainder
231 #define __ieee754_scalb scalb
232 #define __ieee754_sqrtf sqrtf
233 #define __ieee754_acosf acosf
234 #define __ieee754_acoshf acoshf
235 #define __ieee754_logf logf
236 #define __ieee754_atanhf atanhf
237 #define __ieee754_asinf asinf
238 #define __ieee754_atan2f atan2f
239 #define __ieee754_expf expf
240 #define __ieee754_coshf coshf
241 #define __ieee754_fmodf fmodf
242 #define __ieee754_powf powf
243 #define __ieee754_lgammaf lgammaf
244 #define __ieee754_gammaf gammaf
245 #define __ieee754_lgammaf_r lgammaf_r
246 #define __ieee754_gammaf_r gammaf_r
247 #define __ieee754_log2f log2f
248 #define __ieee754_log10f log10f
249 #define __ieee754_sinhf sinhf
250 #define __ieee754_hypotf hypotf
251 #define __ieee754_j0f j0f
252 #define __ieee754_j1f j1f
253 #define __ieee754_y0f y0f
254 #define __ieee754_y1f y1f
255 #define __ieee754_jnf jnf
256 #define __ieee754_ynf ynf
257 #define __ieee754_remainderf remainderf
258 #define __ieee754_scalbf scalbf
260 /* Under FreeBSD, int32_t and int are the same thing. On AROS it may not be,
261 * which causes the build to fail. This is a FreeBSD bug (prototypes don't
262 * match the functions proper), so we work around it with defines below. */
264 /* fdlibm kernel function */
265 #ifndef INLINE_REM_PIO2
266 #ifndef __AROS__
267 int __ieee754_rem_pio2(double,double*);
268 #else
269 int32_t __ieee754_rem_pio2(double,double*);
270 #endif
271 #endif
272 double __kernel_sin(double,double,int);
273 double __kernel_cos(double,double);
274 double __kernel_tan(double,double,int);
275 #ifndef __AROS__
276 int __kernel_rem_pio2(double*,double*,int,int,int,const int*);
277 #else
278 int __kernel_rem_pio2(double*,double*,int,int,int,const int32_t*);
279 #endif
281 /* float versions of fdlibm kernel functions */
282 #ifndef INLINE_REM_PIO2F
283 #ifndef __AROS__
284 int __ieee754_rem_pio2f(float,float*);
285 #else
286 int32_t __ieee754_rem_pio2f(float,float*);
287 #endif
288 #endif
289 #ifndef INLINE_KERNEL_SINDF
290 float __kernel_sindf(double);
291 #endif
292 #ifndef INLINE_KERNEL_COSDF
293 float __kernel_cosdf(double);
294 #endif
295 #ifndef INLINE_KERNEL_TANDF
296 float __kernel_tandf(double,int);
297 #endif
298 #ifndef __AROS__
299 int __kernel_rem_pio2f(float*,float*,int,int,int,const int*);
300 #else
301 int __kernel_rem_pio2f(float*,float*,int,int,int,const int32_t*);
302 #endif
304 #endif /* !_MATH_PRIVATE_H_ */