mlib update: use u_int32_t like the original source to minimise changes
[cake.git] / compiler / mlib / math_private.h
blob31b7bfcca5ac30ce031c306e49caf2ac1f809aa9
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 * from: $FreeBSD: src/lib/msun/src/math_private.h,v 1.6 1999/08/28 00:06:43 peter Exp $
15 * $Id$
18 #ifndef _MATH_PRIVATE_H_
19 #define _MATH_PRIVATE_H_
21 #include <aros/system.h>
22 #include <stdint.h>
24 /* Upstream code uses u_int32_t a lot, but AROS does not define it. Defining
25 * * it here means we can keep changes to the code to a minimum. */
26 #define u_int32_t uint32_t
28 /* The original fdlibm code used statements like:
29 n0 = ((*(int*)&one)>>29)^1; * index of high word *
30 ix0 = *(n0+(int*)&x); * high word of x *
31 ix1 = *((1-n0)+(int*)&x); * low word of x *
32 to dig two 32 bit words out of the 64 bit IEEE floating point
33 value. That is non-ANSI, and, moreover, the gcc instruction
34 scheduler gets it wrong. We instead use the following macros.
35 Unlike the original code, we determine the endianness at compile
36 time, not at run time; I don't see much benefit to selecting
37 endianness at run time. */
39 /* A union which permits us to convert between a double and two 32 bit
40 ints. */
42 #if AROS_BIG_ENDIAN == 1
44 typedef union
46 double value;
47 struct
49 u_int32_t msw;
50 u_int32_t lsw;
51 } parts;
52 } ieee_double_shape_type;
54 #endif
56 #if AROS_BIG_ENDIAN == 0
58 typedef union
60 double value;
61 struct
63 u_int32_t lsw;
64 u_int32_t msw;
65 } parts;
66 } ieee_double_shape_type;
68 #endif
70 /* Get two 32 bit ints from a double. */
72 #define EXTRACT_WORDS(ix0,ix1,d) \
73 do { \
74 ieee_double_shape_type ew_u; \
75 ew_u.value = (d); \
76 (ix0) = ew_u.parts.msw; \
77 (ix1) = ew_u.parts.lsw; \
78 } while (0)
80 /* Get the more significant 32 bit int from a double. */
82 #define GET_HIGH_WORD(i,d) \
83 do { \
84 ieee_double_shape_type gh_u; \
85 gh_u.value = (d); \
86 (i) = gh_u.parts.msw; \
87 } while (0)
89 /* Get the less significant 32 bit int from a double. */
91 #define GET_LOW_WORD(i,d) \
92 do { \
93 ieee_double_shape_type gl_u; \
94 gl_u.value = (d); \
95 (i) = gl_u.parts.lsw; \
96 } while (0)
98 /* Set a double from two 32 bit ints. */
100 #define INSERT_WORDS(d,ix0,ix1) \
101 do { \
102 ieee_double_shape_type iw_u; \
103 iw_u.parts.msw = (ix0); \
104 iw_u.parts.lsw = (ix1); \
105 (d) = iw_u.value; \
106 } while (0)
108 /* Set the more significant 32 bits of a double from an int. */
110 #define SET_HIGH_WORD(d,v) \
111 do { \
112 ieee_double_shape_type sh_u; \
113 sh_u.value = (d); \
114 sh_u.parts.msw = (v); \
115 (d) = sh_u.value; \
116 } while (0)
118 /* Set the less significant 32 bits of a double from an int. */
120 #define SET_LOW_WORD(d,v) \
121 do { \
122 ieee_double_shape_type sl_u; \
123 sl_u.value = (d); \
124 sl_u.parts.lsw = (v); \
125 (d) = sl_u.value; \
126 } while (0)
128 /* A union which permits us to convert between a float and a 32 bit
129 int. */
131 typedef union
133 float value;
134 u_int32_t word;
135 } ieee_float_shape_type;
137 /* Get a 32 bit int from a float. */
139 #define GET_FLOAT_WORD(i,d) \
140 do { \
141 ieee_float_shape_type gf_u; \
142 gf_u.value = (d); \
143 (i) = gf_u.word; \
144 } while (0)
146 /* Set a float from a 32 bit int. */
148 #define SET_FLOAT_WORD(d,i) \
149 do { \
150 ieee_float_shape_type sf_u; \
151 sf_u.word = (i); \
152 (d) = sf_u.value; \
153 } while (0)
155 /* ieee style elementary functions */
156 extern double __ieee754_sqrt (double);
157 extern double __ieee754_acos (double);
158 extern double __ieee754_acosh (double);
159 extern double __ieee754_log (double);
160 extern double __ieee754_atanh (double);
161 extern double __ieee754_asin (double);
162 extern double __ieee754_atan2 (double,double);
163 extern double __ieee754_exp (double);
164 extern double __ieee754_cosh (double);
165 extern double __ieee754_fmod (double,double);
166 extern double __ieee754_pow (double,double);
167 extern double __ieee754_lgamma_r (double,int *);
168 extern double __ieee754_gamma_r (double,int *);
169 extern double __ieee754_lgamma (double);
170 extern double __ieee754_gamma (double);
171 extern double __ieee754_log10 (double);
172 extern double __ieee754_sinh (double);
173 extern double __ieee754_hypot (double,double);
174 extern double __ieee754_j0 (double);
175 extern double __ieee754_j1 (double);
176 extern double __ieee754_y0 (double);
177 extern double __ieee754_y1 (double);
178 extern double __ieee754_jn (int,double);
179 extern double __ieee754_yn (int,double);
180 extern double __ieee754_remainder (double,double);
181 extern int32_t __ieee754_rem_pio2 (double,double*);
182 extern double __ieee754_scalb (double,double);
184 /* fdlibm kernel function */
185 extern double __kernel_standard (double,double,int);
186 extern double __kernel_sin (double,double,int);
187 extern double __kernel_cos (double,double);
188 extern double __kernel_tan (double,double,int);
189 extern int __kernel_rem_pio2 (double*,double*,int,int,int,const int32_t*);
192 /* ieee style elementary float functions */
193 extern float __ieee754_sqrtf (float);
194 extern float __ieee754_acosf (float);
195 extern float __ieee754_acoshf (float);
196 extern float __ieee754_logf (float);
197 extern float __ieee754_atanhf (float);
198 extern float __ieee754_asinf (float);
199 extern float __ieee754_atan2f (float,float);
200 extern float __ieee754_expf (float);
201 extern float __ieee754_coshf (float);
202 extern float __ieee754_fmodf (float,float);
203 extern float __ieee754_powf (float,float);
204 extern float __ieee754_lgammaf_r (float,int *);
205 extern float __ieee754_gammaf_r (float,int *);
206 extern float __ieee754_lgammaf (float);
207 extern float __ieee754_gammaf (float);
208 extern float __ieee754_log10f (float);
209 extern float __ieee754_sinhf (float);
210 extern float __ieee754_hypotf (float,float);
211 extern float __ieee754_j0f (float);
212 extern float __ieee754_j1f (float);
213 extern float __ieee754_y0f (float);
214 extern float __ieee754_y1f (float);
215 extern float __ieee754_jnf (int,float);
216 extern float __ieee754_ynf (int,float);
217 extern float __ieee754_remainderf (float,float);
218 extern int32_t __ieee754_rem_pio2f (float,float*);
219 extern float __ieee754_scalbf (float,float);
221 /* float versions of fdlibm kernel functions */
222 extern float __kernel_sinf (float,float,int);
223 extern float __kernel_cosf (float,float);
224 extern float __kernel_tanf (float,float,int);
225 extern int __kernel_rem_pio2f (float*,float*,int,int,int,const int32_t*);
228 This is how to specify which are implemented in assembler,
229 unfortunately we do not do this quite yet.
230 #ifdef __alpha__
232 #define __generic___ieee754_acos __ieee754_acos
233 #define __generic___ieee754_asin __ieee754_asin
234 #define __generic___ieee754_atan2 __ieee754_atan2
235 #define __generic___ieee754_exp __ieee754_exp
236 #define __generic___ieee754_fmod __ieee754_fmod
237 #define __generic___ieee754_log __ieee754_log
238 #define __generic___ieee754_log10 __ieee754_log10
239 #define __generic___ieee754_remainder __ieee754_remainder
240 #define __generic___ieee754_scalb __ieee754_scalb
241 #define __generic___ieee754_sqrt __ieee754_sqrt
242 #define __generic_atan atan
243 #define __generic_ceil ceil
244 #define __generic_copysign copysign
245 #define __generic_cos cos
246 #define __generic_finite finite
247 #define __generic_floor floor
248 #define __generic_ilogb ilogb
249 #define __generic_log1p log1p
250 #define __generic_logb logb
251 #define __generic_rint rint
252 #define __generic_scalbn scalbn
253 #define __generic_significand significand
254 #define __generic_sin sin
255 #define __generic_tan tan
257 #endif
260 #endif /* _MATH_PRIVATE_H_ */