OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [newlib-1.10.0/] [newlib/] [libm/] [common/] [fdlibm.h] - Blame information for rev 1773

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1010 ivang
 
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
/* Most routines need to check whether a float is finite, infinite, or not a
22
   number, and many need to know whether the result of an operation will
23
   overflow.  These conditions depend on whether the largest exponent is
24
   used for NaNs & infinities, or whether it's used for finite numbers.  The
25
   macros below wrap up that kind of information:
26
 
27
   FLT_UWORD_IS_FINITE(X)
28
        True if a positive float with bitmask X is finite.
29
 
30
   FLT_UWORD_IS_NAN(X)
31
        True if a positive float with bitmask X is not a number.
32
 
33
   FLT_UWORD_IS_INFINITE(X)
34
        True if a positive float with bitmask X is +infinity.
35
 
36
   FLT_UWORD_MAX
37
        The bitmask of FLT_MAX.
38
 
39
   FLT_UWORD_HALF_MAX
40
        The bitmask of FLT_MAX/2.
41
 
42
   FLT_UWORD_EXP_MAX
43
        The bitmask of the largest finite exponent (129 if the largest
44
        exponent is used for finite numbers, 128 otherwise).
45
 
46
   FLT_UWORD_LOG_MAX
47
        The bitmask of log(FLT_MAX), rounded down.  This value is the largest
48
        input that can be passed to exp() without producing overflow.
49
 
50
   FLT_UWORD_LOG_2MAX
51
        The bitmask of log(2*FLT_MAX), rounded down.  This value is the
52
        largest input than can be passed to cosh() without producing
53
        overflow.
54
 
55
   FLT_LARGEST_EXP
56
        The largest biased exponent that can be used for finite numbers
57
        (255 if the largest exponent is used for finite numbers, 254
58
        otherwise) */
59
 
60
#ifdef _FLT_LARGEST_EXPONENT_IS_NORMAL
61
#define FLT_UWORD_IS_FINITE(x) 1
62
#define FLT_UWORD_IS_NAN(x) 0
63
#define FLT_UWORD_IS_INFINITE(x) 0
64
#define FLT_UWORD_MAX 0x7fffffff
65
#define FLT_UWORD_EXP_MAX 0x43010000
66
#define FLT_UWORD_LOG_MAX 0x42b2d4fc
67
#define FLT_UWORD_LOG_2MAX 0x42b437e0
68
#define HUGE ((float)0X1.FFFFFEP128)
69
#else
70
#define FLT_UWORD_IS_FINITE(x) ((x)<0x7f800000L)
71
#define FLT_UWORD_IS_NAN(x) ((x)>0x7f800000L)
72
#define FLT_UWORD_IS_INFINITE(x) ((x)==0x7f800000L)
73
#define FLT_UWORD_MAX 0x7f7fffff
74
#define FLT_UWORD_EXP_MAX 0x43000000
75
#define FLT_UWORD_LOG_MAX 0x42b17217
76
#define FLT_UWORD_LOG_2MAX 0x42b2d4fc
77
#define HUGE ((float)3.40282346638528860e+38)
78
#endif
79
#define FLT_UWORD_HALF_MAX (FLT_UWORD_MAX-(1<<23))
80
#define FLT_LARGEST_EXP (FLT_UWORD_MAX>>23)
81
 
82
/* Many routines check for zero and subnormal numbers.  Such things depend
83
   on whether the target supports denormals or not:
84
 
85
   FLT_UWORD_IS_ZERO(X)
86
        True if a positive float with bitmask X is +0.  Without denormals,
87
        any float with a zero exponent is a +0 representation.  With
88
        denormals, the only +0 representation is a 0 bitmask.
89
 
90
   FLT_UWORD_IS_SUBNORMAL(X)
91
        True if a non-zero positive float with bitmask X is subnormal.
92
        (Routines should check for zeros first.)
93
 
94
   FLT_UWORD_MIN
95
        The bitmask of the smallest float above +0.  Call this number
96
        REAL_FLT_MIN...
97
 
98
   FLT_UWORD_EXP_MIN
99
        The bitmask of the float representation of REAL_FLT_MIN's exponent.
100
 
101
   FLT_UWORD_LOG_MIN
102
        The bitmask of |log(REAL_FLT_MIN)|, rounding down.
103
 
104
   FLT_SMALLEST_EXP
105
        REAL_FLT_MIN's exponent - EXP_BIAS (1 if denormals are not supported,
106
        -22 if they are).
107
*/
108
 
109
#ifdef _FLT_NO_DENORMALS
110
#define FLT_UWORD_IS_ZERO(x) ((x)<0x00800000L)
111
#define FLT_UWORD_IS_SUBNORMAL(x) 0
112
#define FLT_UWORD_MIN 0x00800000
113
#define FLT_UWORD_EXP_MIN 0x42fc0000
114
#define FLT_UWORD_LOG_MIN 0x42aeac50
115
#define FLT_SMALLEST_EXP 1
116
#else
117
#define FLT_UWORD_IS_ZERO(x) ((x)==0)
118
#define FLT_UWORD_IS_SUBNORMAL(x) ((x)<0x00800000L)
119
#define FLT_UWORD_MIN 0x00000001
120
#define FLT_UWORD_EXP_MIN 0x43160000
121
#define FLT_UWORD_LOG_MIN 0x42cff1b5
122
#define FLT_SMALLEST_EXP -22
123
#endif
124
 
125
#ifdef __STDC__
126
#define __P(p)  p
127
#else
128
#define __P(p)  ()
129
#endif
130
 
131
/*
132
 * set X_TLOSS = pi*2**52, which is possibly defined in <values.h>
133
 * (one may replace the following line by "#include <values.h>")
134
 */
135
 
136
#define X_TLOSS         1.41484755040568800000e+16 
137
 
138
/* Functions that are not documented, and are not in <math.h>.  */
139
 
140
extern double logb __P((double));
141
#ifdef _SCALB_INT
142
extern double scalb __P((double, int));
143
#else
144
extern double scalb __P((double, double));
145
#endif
146
extern double significand __P((double));
147
 
148
/* ieee style elementary functions */
149
extern double __ieee754_sqrt __P((double));
150
extern double __ieee754_acos __P((double));
151
extern double __ieee754_acosh __P((double));
152
extern double __ieee754_log __P((double));
153
extern double __ieee754_atanh __P((double));
154
extern double __ieee754_asin __P((double));
155
extern double __ieee754_atan2 __P((double,double));
156
extern double __ieee754_exp __P((double));
157
extern double __ieee754_cosh __P((double));
158
extern double __ieee754_fmod __P((double,double));
159
extern double __ieee754_pow __P((double,double));
160
extern double __ieee754_lgamma_r __P((double,int *));
161
extern double __ieee754_gamma_r __P((double,int *));
162
extern double __ieee754_log10 __P((double));
163
extern double __ieee754_sinh __P((double));
164
extern double __ieee754_hypot __P((double,double));
165
extern double __ieee754_j0 __P((double));
166
extern double __ieee754_j1 __P((double));
167
extern double __ieee754_y0 __P((double));
168
extern double __ieee754_y1 __P((double));
169
extern double __ieee754_jn __P((int,double));
170
extern double __ieee754_yn __P((int,double));
171
extern double __ieee754_remainder __P((double,double));
172
extern __int32_t __ieee754_rem_pio2 __P((double,double*));
173
#ifdef _SCALB_INT
174
extern double __ieee754_scalb __P((double,int));
175
#else
176
extern double __ieee754_scalb __P((double,double));
177
#endif
178
 
179
/* fdlibm kernel function */
180
extern double __kernel_standard __P((double,double,int));
181
extern double __kernel_sin __P((double,double,int));
182
extern double __kernel_cos __P((double,double));
183
extern double __kernel_tan __P((double,double,int));
184
extern int    __kernel_rem_pio2 __P((double*,double*,int,int,int,const __int32_t*));
185
 
186
/* Undocumented float functions.  */
187
extern float logbf __P((float));
188
#ifdef _SCALB_INT
189
extern float scalbf __P((float, int));
190
#else
191
extern float scalbf __P((float, float));
192
#endif
193
extern float significandf __P((float));
194
 
195
/* ieee style elementary float functions */
196
extern float __ieee754_sqrtf __P((float));
197
extern float __ieee754_acosf __P((float));
198
extern float __ieee754_acoshf __P((float));
199
extern float __ieee754_logf __P((float));
200
extern float __ieee754_atanhf __P((float));
201
extern float __ieee754_asinf __P((float));
202
extern float __ieee754_atan2f __P((float,float));
203
extern float __ieee754_expf __P((float));
204
extern float __ieee754_coshf __P((float));
205
extern float __ieee754_fmodf __P((float,float));
206
extern float __ieee754_powf __P((float,float));
207
extern float __ieee754_lgammaf_r __P((float,int *));
208
extern float __ieee754_gammaf_r __P((float,int *));
209
extern float __ieee754_log10f __P((float));
210
extern float __ieee754_sinhf __P((float));
211
extern float __ieee754_hypotf __P((float,float));
212
extern float __ieee754_j0f __P((float));
213
extern float __ieee754_j1f __P((float));
214
extern float __ieee754_y0f __P((float));
215
extern float __ieee754_y1f __P((float));
216
extern float __ieee754_jnf __P((int,float));
217
extern float __ieee754_ynf __P((int,float));
218
extern float __ieee754_remainderf __P((float,float));
219
extern __int32_t __ieee754_rem_pio2f __P((float,float*));
220
#ifdef _SCALB_INT
221
extern float __ieee754_scalbf __P((float,int));
222
#else
223
extern float __ieee754_scalbf __P((float,float));
224
#endif
225
 
226
/* float versions of fdlibm kernel functions */
227
extern float __kernel_sinf __P((float,float,int));
228
extern float __kernel_cosf __P((float,float));
229
extern float __kernel_tanf __P((float,float,int));
230
extern int   __kernel_rem_pio2f __P((float*,float*,int,int,int,const __int32_t*));
231
 
232
/* The original code used statements like
233
        n0 = ((*(int*)&one)>>29)^1;             * index of high word *
234
        ix0 = *(n0+(int*)&x);                   * high word of x *
235
        ix1 = *((1-n0)+(int*)&x);               * low word of x *
236
   to dig two 32 bit words out of the 64 bit IEEE floating point
237
   value.  That is non-ANSI, and, moreover, the gcc instruction
238
   scheduler gets it wrong.  We instead use the following macros.
239
   Unlike the original code, we determine the endianness at compile
240
   time, not at run time; I don't see much benefit to selecting
241
   endianness at run time.  */
242
 
243
#ifndef __IEEE_BIG_ENDIAN
244
#ifndef __IEEE_LITTLE_ENDIAN
245
 #error Must define endianness
246
#endif
247
#endif
248
 
249
/* A union which permits us to convert between a double and two 32 bit
250
   ints.  */
251
 
252
#ifdef __IEEE_BIG_ENDIAN
253
 
254
typedef union
255
{
256
  double value;
257
  struct
258
  {
259
    __uint32_t msw;
260
    __uint32_t lsw;
261
  } parts;
262
} ieee_double_shape_type;
263
 
264
#endif
265
 
266
#ifdef __IEEE_LITTLE_ENDIAN
267
 
268
typedef union
269
{
270
  double value;
271
  struct
272
  {
273
    __uint32_t lsw;
274
    __uint32_t msw;
275
  } parts;
276
} ieee_double_shape_type;
277
 
278
#endif
279
 
280
/* Get two 32 bit ints from a double.  */
281
 
282
#define EXTRACT_WORDS(ix0,ix1,d)                                \
283
do {                                                            \
284
  ieee_double_shape_type ew_u;                                  \
285
  ew_u.value = (d);                                             \
286
  (ix0) = ew_u.parts.msw;                                       \
287
  (ix1) = ew_u.parts.lsw;                                       \
288
} while (0)
289
 
290
/* Get the more significant 32 bit int from a double.  */
291
 
292
#define GET_HIGH_WORD(i,d)                                      \
293
do {                                                            \
294
  ieee_double_shape_type gh_u;                                  \
295
  gh_u.value = (d);                                             \
296
  (i) = gh_u.parts.msw;                                         \
297
} while (0)
298
 
299
/* Get the less significant 32 bit int from a double.  */
300
 
301
#define GET_LOW_WORD(i,d)                                       \
302
do {                                                            \
303
  ieee_double_shape_type gl_u;                                  \
304
  gl_u.value = (d);                                             \
305
  (i) = gl_u.parts.lsw;                                         \
306
} while (0)
307
 
308
/* Set a double from two 32 bit ints.  */
309
 
310
#define INSERT_WORDS(d,ix0,ix1)                                 \
311
do {                                                            \
312
  ieee_double_shape_type iw_u;                                  \
313
  iw_u.parts.msw = (ix0);                                       \
314
  iw_u.parts.lsw = (ix1);                                       \
315
  (d) = iw_u.value;                                             \
316
} while (0)
317
 
318
/* Set the more significant 32 bits of a double from an int.  */
319
 
320
#define SET_HIGH_WORD(d,v)                                      \
321
do {                                                            \
322
  ieee_double_shape_type sh_u;                                  \
323
  sh_u.value = (d);                                             \
324
  sh_u.parts.msw = (v);                                         \
325
  (d) = sh_u.value;                                             \
326
} while (0)
327
 
328
/* Set the less significant 32 bits of a double from an int.  */
329
 
330
#define SET_LOW_WORD(d,v)                                       \
331
do {                                                            \
332
  ieee_double_shape_type sl_u;                                  \
333
  sl_u.value = (d);                                             \
334
  sl_u.parts.lsw = (v);                                         \
335
  (d) = sl_u.value;                                             \
336
} while (0)
337
 
338
/* A union which permits us to convert between a float and a 32 bit
339
   int.  */
340
 
341
typedef union
342
{
343
  float value;
344
  __uint32_t word;
345
} ieee_float_shape_type;
346
 
347
/* Get a 32 bit int from a float.  */
348
 
349
#define GET_FLOAT_WORD(i,d)                                     \
350
do {                                                            \
351
  ieee_float_shape_type gf_u;                                   \
352
  gf_u.value = (d);                                             \
353
  (i) = gf_u.word;                                              \
354
} while (0)
355
 
356
/* Set a float from a 32 bit int.  */
357
 
358
#define SET_FLOAT_WORD(d,i)                                     \
359
do {                                                            \
360
  ieee_float_shape_type sf_u;                                   \
361
  sf_u.word = (i);                                              \
362
  (d) = sf_u.value;                                             \
363
} while (0)

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.