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