comparison src/libm/math_private.h @ 2756:a98604b691c8

Expanded the libm support and put it into a separate directory.
author Sam Lantinga <slouken@libsdl.org>
date Mon, 15 Sep 2008 06:33:23 +0000
parents
children 02aa80d7905f
comparison
equal deleted inserted replaced
2755:2a3ec308d995 2756:a98604b691c8
1 /*
2 * ====================================================
3 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
4 *
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 * ====================================================
10 */
11
12 /*
13 * from: @(#)fdlibm.h 5.1 93/09/24
14 * $Id: math_private.h,v 1.3 2004/02/09 07:10:38 andersen Exp $
15 */
16
17 #ifndef _MATH_PRIVATE_H_
18 #define _MATH_PRIVATE_H_
19
20 /*#include <endian.h>*/
21 #include <sys/types.h>
22
23 #define attribute_hidden
24 #define libm_hidden_proto(x)
25 #define libm_hidden_def(x)
26
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. */
37
38 /* A union which permits us to convert between a double and two 32 bit
39 ints. */
40
41 /*
42 * Math on arm is special:
43 * For FPA, float words are always big-endian.
44 * For VFP, floats words follow the memory system mode.
45 */
46
47 #if (__BYTE_ORDER == __BIG_ENDIAN) || \
48 (!defined(__VFP_FP__) && (defined(__arm__) || defined(__thumb__)))
49
50 typedef union
51 {
52 double value;
53 struct
54 {
55 u_int32_t msw;
56 u_int32_t lsw;
57 } parts;
58 } ieee_double_shape_type;
59
60 #else
61
62 typedef union
63 {
64 double value;
65 struct
66 {
67 u_int32_t lsw;
68 u_int32_t msw;
69 } parts;
70 } ieee_double_shape_type;
71
72 #endif
73
74 /* Get two 32 bit ints from a double. */
75
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)
83
84 /* Get the more significant 32 bit int from a double. */
85
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)
92
93 /* Get the less significant 32 bit int from a double. */
94
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
102 /* Set a double from two 32 bit ints. */
103
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)
111
112 /* Set the more significant 32 bits of a double from an int. */
113
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)
121
122 /* Set the less significant 32 bits of a double from an int. */
123
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)
131
132 /* A union which permits us to convert between a float and a 32 bit
133 int. */
134
135 typedef union
136 {
137 float value;
138 u_int32_t word;
139 } ieee_float_shape_type;
140
141 /* Get a 32 bit int from a float. */
142
143 #define GET_FLOAT_WORD(i,d) \
144 do { \
145 ieee_float_shape_type gf_u; \
146 gf_u.value = (d); \
147 (i) = gf_u.word; \
148 } while (0)
149
150 /* Set a float from a 32 bit int. */
151
152 #define SET_FLOAT_WORD(d,i) \
153 do { \
154 ieee_float_shape_type sf_u; \
155 sf_u.word = (i); \
156 (d) = sf_u.value; \
157 } while (0)
158
159 /* ieee style elementary functions */
160 extern double
161 __ieee754_sqrt(double)
162 attribute_hidden;
163 extern double __ieee754_acos(double) attribute_hidden;
164 extern double __ieee754_acosh(double) attribute_hidden;
165 extern double __ieee754_log(double) attribute_hidden;
166 extern double __ieee754_atanh(double) attribute_hidden;
167 extern double __ieee754_asin(double) attribute_hidden;
168 extern double __ieee754_atan2(double, double) attribute_hidden;
169 extern double __ieee754_exp(double) attribute_hidden;
170 extern double __ieee754_cosh(double) attribute_hidden;
171 extern double __ieee754_fmod(double, double) attribute_hidden;
172 extern double __ieee754_pow(double, double) attribute_hidden;
173 extern double __ieee754_lgamma_r(double, int *) attribute_hidden;
174 extern double __ieee754_gamma_r(double, int *) attribute_hidden;
175 extern double __ieee754_lgamma(double) attribute_hidden;
176 extern double __ieee754_gamma(double) attribute_hidden;
177 extern double __ieee754_log10(double) attribute_hidden;
178 extern double __ieee754_sinh(double) attribute_hidden;
179 extern double __ieee754_hypot(double, double) attribute_hidden;
180 extern double __ieee754_j0(double) attribute_hidden;
181 extern double __ieee754_j1(double) attribute_hidden;
182 extern double __ieee754_y0(double) attribute_hidden;
183 extern double __ieee754_y1(double) attribute_hidden;
184 extern double __ieee754_jn(int, double) attribute_hidden;
185 extern double __ieee754_yn(int, double) attribute_hidden;
186 extern double __ieee754_remainder(double, double) attribute_hidden;
187 extern int __ieee754_rem_pio2(double, double *) attribute_hidden;
188 #if defined(_SCALB_INT)
189 extern double __ieee754_scalb(double, int) attribute_hidden;
190 #else
191 extern double __ieee754_scalb(double, double) attribute_hidden;
192 #endif
193
194 /* fdlibm kernel function */
195 #ifndef _IEEE_LIBM
196 extern double __kernel_standard(double, double, int) attribute_hidden;
197 #endif
198 extern double __kernel_sin(double, double, int) attribute_hidden;
199 extern double __kernel_cos(double, double) attribute_hidden;
200 extern double __kernel_tan(double, double, int) attribute_hidden;
201 extern int __kernel_rem_pio2(double *, double *, int, int, int,
202 const int *) attribute_hidden;
203
204 #endif /* _MATH_PRIVATE_H_ */