1 |
39 |
lampret |
|
2 |
|
|
/* @(#)fdlibm.h 5.1 93/09/24 */
|
3 |
|
|
/*
|
4 |
|
|
* ====================================================
|
5 |
|
|
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
|
6 |
|
|
*
|
7 |
|
|
* Developed at SunPro, a Sun Microsystems, Inc. business.
|
8 |
|
|
* Permission to use, copy, modify, and distribute this
|
9 |
|
|
* software is freely granted, provided that this notice
|
10 |
|
|
* is preserved.
|
11 |
|
|
* ====================================================
|
12 |
|
|
*/
|
13 |
|
|
|
14 |
|
|
/* CYGNUS LOCAL: Include files. */
|
15 |
|
|
#include <math.h>
|
16 |
|
|
#include <machine/ieeefp.h>
|
17 |
|
|
|
18 |
|
|
/* CYGNUS LOCAL: Default to XOPEN_MODE. */
|
19 |
|
|
#define _XOPEN_MODE
|
20 |
|
|
|
21 |
|
|
#ifdef __STDC__
|
22 |
|
|
#define __P(p) p
|
23 |
|
|
#else
|
24 |
|
|
#define __P(p) ()
|
25 |
|
|
#endif
|
26 |
|
|
|
27 |
|
|
#define HUGE ((float)3.40282346638528860e+38)
|
28 |
|
|
|
29 |
|
|
/*
|
30 |
|
|
* set X_TLOSS = pi*2**52, which is possibly defined in <values.h>
|
31 |
|
|
* (one may replace the following line by "#include <values.h>")
|
32 |
|
|
*/
|
33 |
|
|
|
34 |
|
|
#define X_TLOSS 1.41484755040568800000e+16
|
35 |
|
|
|
36 |
|
|
/* Functions that are not documented, and are not in <math.h>. */
|
37 |
|
|
|
38 |
|
|
extern double logb __P((double));
|
39 |
|
|
#ifdef _SCALB_INT
|
40 |
|
|
extern double scalb __P((double, int));
|
41 |
|
|
#else
|
42 |
|
|
extern double scalb __P((double, double));
|
43 |
|
|
#endif
|
44 |
|
|
extern double significand __P((double));
|
45 |
|
|
|
46 |
|
|
/* ieee style elementary functions */
|
47 |
|
|
extern double __ieee754_sqrt __P((double));
|
48 |
|
|
extern double __ieee754_acos __P((double));
|
49 |
|
|
extern double __ieee754_acosh __P((double));
|
50 |
|
|
extern double __ieee754_log __P((double));
|
51 |
|
|
extern double __ieee754_atanh __P((double));
|
52 |
|
|
extern double __ieee754_asin __P((double));
|
53 |
|
|
extern double __ieee754_atan2 __P((double,double));
|
54 |
|
|
extern double __ieee754_exp __P((double));
|
55 |
|
|
extern double __ieee754_cosh __P((double));
|
56 |
|
|
extern double __ieee754_fmod __P((double,double));
|
57 |
|
|
extern double __ieee754_pow __P((double,double));
|
58 |
|
|
extern double __ieee754_lgamma_r __P((double,int *));
|
59 |
|
|
extern double __ieee754_gamma_r __P((double,int *));
|
60 |
|
|
extern double __ieee754_log10 __P((double));
|
61 |
|
|
extern double __ieee754_sinh __P((double));
|
62 |
|
|
extern double __ieee754_hypot __P((double,double));
|
63 |
|
|
extern double __ieee754_j0 __P((double));
|
64 |
|
|
extern double __ieee754_j1 __P((double));
|
65 |
|
|
extern double __ieee754_y0 __P((double));
|
66 |
|
|
extern double __ieee754_y1 __P((double));
|
67 |
|
|
extern double __ieee754_jn __P((int,double));
|
68 |
|
|
extern double __ieee754_yn __P((int,double));
|
69 |
|
|
extern double __ieee754_remainder __P((double,double));
|
70 |
|
|
extern __int32_t __ieee754_rem_pio2 __P((double,double*));
|
71 |
|
|
#ifdef _SCALB_INT
|
72 |
|
|
extern double __ieee754_scalb __P((double,int));
|
73 |
|
|
#else
|
74 |
|
|
extern double __ieee754_scalb __P((double,double));
|
75 |
|
|
#endif
|
76 |
|
|
|
77 |
|
|
/* fdlibm kernel function */
|
78 |
|
|
extern double __kernel_standard __P((double,double,int));
|
79 |
|
|
extern double __kernel_sin __P((double,double,int));
|
80 |
|
|
extern double __kernel_cos __P((double,double));
|
81 |
|
|
extern double __kernel_tan __P((double,double,int));
|
82 |
|
|
extern int __kernel_rem_pio2 __P((double*,double*,int,int,int,const __int32_t*));
|
83 |
|
|
|
84 |
|
|
/* Undocumented float functions. */
|
85 |
|
|
extern float logbf __P((float));
|
86 |
|
|
#ifdef _SCALB_INT
|
87 |
|
|
extern float scalbf __P((float, int));
|
88 |
|
|
#else
|
89 |
|
|
extern float scalbf __P((float, float));
|
90 |
|
|
#endif
|
91 |
|
|
extern float significandf __P((float));
|
92 |
|
|
|
93 |
|
|
/* ieee style elementary float functions */
|
94 |
|
|
extern float __ieee754_sqrtf __P((float));
|
95 |
|
|
extern float __ieee754_acosf __P((float));
|
96 |
|
|
extern float __ieee754_acoshf __P((float));
|
97 |
|
|
extern float __ieee754_logf __P((float));
|
98 |
|
|
extern float __ieee754_atanhf __P((float));
|
99 |
|
|
extern float __ieee754_asinf __P((float));
|
100 |
|
|
extern float __ieee754_atan2f __P((float,float));
|
101 |
|
|
extern float __ieee754_expf __P((float));
|
102 |
|
|
extern float __ieee754_coshf __P((float));
|
103 |
|
|
extern float __ieee754_fmodf __P((float,float));
|
104 |
|
|
extern float __ieee754_powf __P((float,float));
|
105 |
|
|
extern float __ieee754_lgammaf_r __P((float,int *));
|
106 |
|
|
extern float __ieee754_gammaf_r __P((float,int *));
|
107 |
|
|
extern float __ieee754_log10f __P((float));
|
108 |
|
|
extern float __ieee754_sinhf __P((float));
|
109 |
|
|
extern float __ieee754_hypotf __P((float,float));
|
110 |
|
|
extern float __ieee754_j0f __P((float));
|
111 |
|
|
extern float __ieee754_j1f __P((float));
|
112 |
|
|
extern float __ieee754_y0f __P((float));
|
113 |
|
|
extern float __ieee754_y1f __P((float));
|
114 |
|
|
extern float __ieee754_jnf __P((int,float));
|
115 |
|
|
extern float __ieee754_ynf __P((int,float));
|
116 |
|
|
extern float __ieee754_remainderf __P((float,float));
|
117 |
|
|
extern __int32_t __ieee754_rem_pio2f __P((float,float*));
|
118 |
|
|
#ifdef _SCALB_INT
|
119 |
|
|
extern float __ieee754_scalbf __P((float,int));
|
120 |
|
|
#else
|
121 |
|
|
extern float __ieee754_scalbf __P((float,float));
|
122 |
|
|
#endif
|
123 |
|
|
|
124 |
|
|
/* float versions of fdlibm kernel functions */
|
125 |
|
|
extern float __kernel_sinf __P((float,float,int));
|
126 |
|
|
extern float __kernel_cosf __P((float,float));
|
127 |
|
|
extern float __kernel_tanf __P((float,float,int));
|
128 |
|
|
extern int __kernel_rem_pio2f __P((float*,float*,int,int,int,const __int32_t*));
|
129 |
|
|
|
130 |
|
|
/* The original code used statements like
|
131 |
|
|
n0 = ((*(int*)&one)>>29)^1; * index of high word *
|
132 |
|
|
ix0 = *(n0+(int*)&x); * high word of x *
|
133 |
|
|
ix1 = *((1-n0)+(int*)&x); * low word of x *
|
134 |
|
|
to dig two 32 bit words out of the 64 bit IEEE floating point
|
135 |
|
|
value. That is non-ANSI, and, moreover, the gcc instruction
|
136 |
|
|
scheduler gets it wrong. We instead use the following macros.
|
137 |
|
|
Unlike the original code, we determine the endianness at compile
|
138 |
|
|
time, not at run time; I don't see much benefit to selecting
|
139 |
|
|
endianness at run time. */
|
140 |
|
|
|
141 |
|
|
#ifndef __IEEE_BIG_ENDIAN
|
142 |
|
|
#ifndef __IEEE_LITTLE_ENDIAN
|
143 |
|
|
#error Must define endianness
|
144 |
|
|
#endif
|
145 |
|
|
#endif
|
146 |
|
|
|
147 |
|
|
/* A union which permits us to convert between a double and two 32 bit
|
148 |
|
|
ints. */
|
149 |
|
|
|
150 |
|
|
#ifdef __IEEE_BIG_ENDIAN
|
151 |
|
|
|
152 |
|
|
typedef union
|
153 |
|
|
{
|
154 |
|
|
double value;
|
155 |
|
|
struct
|
156 |
|
|
{
|
157 |
|
|
__uint32_t msw;
|
158 |
|
|
__uint32_t lsw;
|
159 |
|
|
} parts;
|
160 |
|
|
} ieee_double_shape_type;
|
161 |
|
|
|
162 |
|
|
#endif
|
163 |
|
|
|
164 |
|
|
#ifdef __IEEE_LITTLE_ENDIAN
|
165 |
|
|
|
166 |
|
|
typedef union
|
167 |
|
|
{
|
168 |
|
|
double value;
|
169 |
|
|
struct
|
170 |
|
|
{
|
171 |
|
|
__uint32_t lsw;
|
172 |
|
|
__uint32_t msw;
|
173 |
|
|
} parts;
|
174 |
|
|
} ieee_double_shape_type;
|
175 |
|
|
|
176 |
|
|
#endif
|
177 |
|
|
|
178 |
|
|
/* Get two 32 bit ints from a double. */
|
179 |
|
|
|
180 |
|
|
#define EXTRACT_WORDS(ix0,ix1,d) \
|
181 |
|
|
do { \
|
182 |
|
|
ieee_double_shape_type ew_u; \
|
183 |
|
|
ew_u.value = (d); \
|
184 |
|
|
(ix0) = ew_u.parts.msw; \
|
185 |
|
|
(ix1) = ew_u.parts.lsw; \
|
186 |
|
|
} while (0)
|
187 |
|
|
|
188 |
|
|
/* Get the more significant 32 bit int from a double. */
|
189 |
|
|
|
190 |
|
|
#define GET_HIGH_WORD(i,d) \
|
191 |
|
|
do { \
|
192 |
|
|
ieee_double_shape_type gh_u; \
|
193 |
|
|
gh_u.value = (d); \
|
194 |
|
|
(i) = gh_u.parts.msw; \
|
195 |
|
|
} while (0)
|
196 |
|
|
|
197 |
|
|
/* Get the less significant 32 bit int from a double. */
|
198 |
|
|
|
199 |
|
|
#define GET_LOW_WORD(i,d) \
|
200 |
|
|
do { \
|
201 |
|
|
ieee_double_shape_type gl_u; \
|
202 |
|
|
gl_u.value = (d); \
|
203 |
|
|
(i) = gl_u.parts.lsw; \
|
204 |
|
|
} while (0)
|
205 |
|
|
|
206 |
|
|
/* Set a double from two 32 bit ints. */
|
207 |
|
|
|
208 |
|
|
#define INSERT_WORDS(d,ix0,ix1) \
|
209 |
|
|
do { \
|
210 |
|
|
ieee_double_shape_type iw_u; \
|
211 |
|
|
iw_u.parts.msw = (ix0); \
|
212 |
|
|
iw_u.parts.lsw = (ix1); \
|
213 |
|
|
(d) = iw_u.value; \
|
214 |
|
|
} while (0)
|
215 |
|
|
|
216 |
|
|
/* Set the more significant 32 bits of a double from an int. */
|
217 |
|
|
|
218 |
|
|
#define SET_HIGH_WORD(d,v) \
|
219 |
|
|
do { \
|
220 |
|
|
ieee_double_shape_type sh_u; \
|
221 |
|
|
sh_u.value = (d); \
|
222 |
|
|
sh_u.parts.msw = (v); \
|
223 |
|
|
(d) = sh_u.value; \
|
224 |
|
|
} while (0)
|
225 |
|
|
|
226 |
|
|
/* Set the less significant 32 bits of a double from an int. */
|
227 |
|
|
|
228 |
|
|
#define SET_LOW_WORD(d,v) \
|
229 |
|
|
do { \
|
230 |
|
|
ieee_double_shape_type sl_u; \
|
231 |
|
|
sl_u.value = (d); \
|
232 |
|
|
sl_u.parts.lsw = (v); \
|
233 |
|
|
(d) = sl_u.value; \
|
234 |
|
|
} while (0)
|
235 |
|
|
|
236 |
|
|
/* A union which permits us to convert between a float and a 32 bit
|
237 |
|
|
int. */
|
238 |
|
|
|
239 |
|
|
typedef union
|
240 |
|
|
{
|
241 |
|
|
float value;
|
242 |
|
|
__uint32_t word;
|
243 |
|
|
} ieee_float_shape_type;
|
244 |
|
|
|
245 |
|
|
/* Get a 32 bit int from a float. */
|
246 |
|
|
|
247 |
|
|
#define GET_FLOAT_WORD(i,d) \
|
248 |
|
|
do { \
|
249 |
|
|
ieee_float_shape_type gf_u; \
|
250 |
|
|
gf_u.value = (d); \
|
251 |
|
|
(i) = gf_u.word; \
|
252 |
|
|
} while (0)
|
253 |
|
|
|
254 |
|
|
/* Set a float from a 32 bit int. */
|
255 |
|
|
|
256 |
|
|
#define SET_FLOAT_WORD(d,i) \
|
257 |
|
|
do { \
|
258 |
|
|
ieee_float_shape_type sf_u; \
|
259 |
|
|
sf_u.word = (i); \
|
260 |
|
|
(d) = sf_u.value; \
|
261 |
|
|
} while (0)
|