comparison packages/language/c/libm/current/src/mathincl/fdlibm.h @ 3337:77f9d3253c3e

Add: Complex number header and library (single and double precision floating point), port from Newlib. Add: Single precision floating point library, port from Newlib. [ Bugzilla 1001539 ]
author vae
date Sun, 25 Aug 2013 14:38:57 +0000
parents 74dbf4c3f2e1
children
comparison
equal deleted inserted replaced
3336:8ecac279f33c 3337:77f9d3253c3e
82 // TYPES 82 // TYPES
83 83
84 typedef cyg_int32 __int32_t; 84 typedef cyg_int32 __int32_t;
85 typedef cyg_uint32 __uint32_t; 85 typedef cyg_uint32 __uint32_t;
86 typedef Cyg_libm_ieee_double_shape_type ieee_double_shape_type; 86 typedef Cyg_libm_ieee_double_shape_type ieee_double_shape_type;
87 typedef Cyg_libm_ieee_float_shape_type ieee_float_shape_type;
88
89 /* Most routines need to check whether a float is finite, infinite, or not a
90 number, and many need to know whether the result of an operation will
91 overflow. These conditions depend on whether the largest exponent is
92 used for NaNs & infinities, or whether it's used for finite numbers. The
93 macros below wrap up that kind of information:
94
95 FLT_UWORD_IS_FINITE(X)
96 True if a positive float with bitmask X is finite.
97
98 FLT_UWORD_IS_NAN(X)
99 True if a positive float with bitmask X is not a number.
100
101 FLT_UWORD_IS_INFINITE(X)
102 True if a positive float with bitmask X is +infinity.
103
104 FLT_UWORD_MAX
105 The bitmask of FLT_MAX.
106
107 FLT_UWORD_HALF_MAX
108 The bitmask of FLT_MAX/2.
109
110 FLT_UWORD_EXP_MAX
111 The bitmask of the largest finite exponent (129 if the largest
112 exponent is used for finite numbers, 128 otherwise).
113
114 FLT_UWORD_LOG_MAX
115 The bitmask of log(FLT_MAX), rounded down. This value is the largest
116 input that can be passed to exp() without producing overflow.
117
118 FLT_UWORD_LOG_2MAX
119 The bitmask of log(2*FLT_MAX), rounded down. This value is the
120 largest input than can be passed to cosh() without producing
121 overflow.
122
123 FLT_LARGEST_EXP
124 The largest biased exponent that can be used for finite numbers
125 (255 if the largest exponent is used for finite numbers, 254
126 otherwise) */
127
128 #ifdef _FLT_LARGEST_EXPONENT_IS_NORMAL
129 #define FLT_UWORD_IS_FINITE(x) 1
130 #define FLT_UWORD_IS_NAN(x) 0
131 #define FLT_UWORD_IS_INFINITE(x) 0
132 #define FLT_UWORD_MAX 0x7fffffff
133 #define FLT_UWORD_EXP_MAX 0x43010000
134 #define FLT_UWORD_LOG_MAX 0x42b2d4fc
135 #define FLT_UWORD_LOG_2MAX 0x42b437e0
136 //#define HUGE ((float)0X1.FFFFFEP128)
137 #else
138 #define FLT_UWORD_IS_FINITE(x) ((x)<0x7f800000L)
139 #define FLT_UWORD_IS_NAN(x) ((x)>0x7f800000L)
140 #define FLT_UWORD_IS_INFINITE(x) ((x)==0x7f800000L)
141 #define FLT_UWORD_MAX 0x7f7fffffL
142 #define FLT_UWORD_EXP_MAX 0x43000000
143 #define FLT_UWORD_LOG_MAX 0x42b17217
144 #define FLT_UWORD_LOG_2MAX 0x42b2d4fc
145 //#define HUGE ((float)3.40282346638528860e+38)
146 #endif
147 #define FLT_UWORD_HALF_MAX (FLT_UWORD_MAX-(1L<<23))
148 #define FLT_LARGEST_EXP (FLT_UWORD_MAX>>23)
149
150 /* Many routines check for zero and subnormal numbers. Such things depend
151 on whether the target supports denormals or not:
152
153 FLT_UWORD_IS_ZERO(X)
154 True if a positive float with bitmask X is +0. Without denormals,
155 any float with a zero exponent is a +0 representation. With
156 denormals, the only +0 representation is a 0 bitmask.
157
158 FLT_UWORD_IS_SUBNORMAL(X)
159 True if a non-zero positive float with bitmask X is subnormal.
160 (Routines should check for zeros first.)
161
162 FLT_UWORD_MIN
163 The bitmask of the smallest float above +0. Call this number
164 REAL_FLT_MIN...
165
166 FLT_UWORD_EXP_MIN
167 The bitmask of the float representation of REAL_FLT_MIN's exponent.
168
169 FLT_UWORD_LOG_MIN
170 The bitmask of |log(REAL_FLT_MIN)|, rounding down.
171
172 FLT_SMALLEST_EXP
173 REAL_FLT_MIN's exponent - EXP_BIAS (1 if denormals are not supported,
174 -22 if they are).
175 */
176
177 #ifdef _FLT_NO_DENORMALS
178 #define FLT_UWORD_IS_ZERO(x) ((x)<0x00800000L)
179 #define FLT_UWORD_IS_SUBNORMAL(x) 0
180 #define FLT_UWORD_MIN 0x00800000
181 #define FLT_UWORD_EXP_MIN 0x42fc0000
182 #define FLT_UWORD_LOG_MIN 0x42aeac50
183 #define FLT_SMALLEST_EXP 1
184 #else
185 #define FLT_UWORD_IS_ZERO(x) ((x)==0)
186 #define FLT_UWORD_IS_SUBNORMAL(x) ((x)<0x00800000L)
187 #define FLT_UWORD_MIN 0x00000001
188 #define FLT_UWORD_EXP_MIN 0x43160000
189 #define FLT_UWORD_LOG_MIN 0x42cff1b5
190 #define FLT_SMALLEST_EXP -22
191 #endif
87 192
88 // MACRO DEFINITIONS 193 // MACRO DEFINITIONS
89 194
90 #ifndef __STDC__ 195 #ifndef __STDC__
91 # define __STDC__ 1 196 # define __STDC__ 1
93 #define CYG_LIBM_HI(__x) (((Cyg_libm_ieee_double_shape_type *)&__x)->parts.msw) 198 #define CYG_LIBM_HI(__x) (((Cyg_libm_ieee_double_shape_type *)&__x)->parts.msw)
94 #define CYG_LIBM_LO(__x) (((Cyg_libm_ieee_double_shape_type *)&__x)->parts.lsw) 199 #define CYG_LIBM_LO(__x) (((Cyg_libm_ieee_double_shape_type *)&__x)->parts.lsw)
95 #define CYG_LIBM_HIp(__x) (((Cyg_libm_ieee_double_shape_type *)__x)->parts.msw) 200 #define CYG_LIBM_HIp(__x) (((Cyg_libm_ieee_double_shape_type *)__x)->parts.msw)
96 #define CYG_LIBM_LOp(__x) (((Cyg_libm_ieee_double_shape_type *)__x)->parts.lsw) 201 #define CYG_LIBM_LOp(__x) (((Cyg_libm_ieee_double_shape_type *)__x)->parts.lsw)
97 202
98 203 #define CYG_LIBM_WORD(__x) (((Cyg_libm_ieee_float_shape_type *)&__x)->asi32)
204
205 /* Get a 32 bit int from a float. */
206
207 #define GET_FLOAT_WORD(i,f) \
208 do { \
209 Cyg_libm_ieee_float_shape_type gf_u; \
210 gf_u.value = (f); \
211 (i) = gf_u.asi32; \
212 } while (0)
213
214 /* Set a float from a 32 bit int. */
215
216 #define SET_FLOAT_WORD(f,i) \
217 do { \
218 Cyg_libm_ieee_float_shape_type sf_u; \
219 sf_u.asi32 = (i); \
220 (f) = sf_u.value; \
221 } while (0)
99 222
100 /* Get two 32 bit ints from a double. */ 223 /* Get two 32 bit ints from a double. */
101 224
102 #define EXTRACT_WORDS(ix0,ix1,d) \ 225 #define EXTRACT_WORDS(ix0,ix1,d) \
103 do { \ 226 do { \
177 }; 300 };
178 301
179 externC int 302 externC int
180 matherr( struct exception * ); // User-overridable error handling - see 303 matherr( struct exception * ); // User-overridable error handling - see
181 // <pkgconf/libm.h> for a discussion 304 // <pkgconf/libm.h> for a discussion
305 struct exceptionf {
306 int type; // One of DOMAIN, SING, OVERFLOW, UNDERFLOW, TLOSS, PLOSS
307 char *name; // Name of the function generating the exception
308 float arg1; // First argument to the function
309 float arg2; // Second argument to the function
310 float retval; // Value to be returned - can be altered by matherr()
311 };
312
313 externC int
314 matherrf( struct exceptionf * );
315
182 #endif // ifdef CYGSYM_LIBM_NO_XOPEN_SVID_NAMESPACE_POLLUTION 316 #endif // ifdef CYGSYM_LIBM_NO_XOPEN_SVID_NAMESPACE_POLLUTION
183
184 317
185 // FUNCTION PROTOTYPES 318 // FUNCTION PROTOTYPES
186 319
187 // IEEE-754 style elementary functions */ 320 // IEEE-754 style elementary functions */
188 321
287 __kernel_tan( double, double, int ); 420 __kernel_tan( double, double, int );
288 421
289 externC int 422 externC int
290 __kernel_rem_pio2( double *, double *, int, int, int, const int * ); 423 __kernel_rem_pio2( double *, double *, int, int, int, const int * );
291 424
425 /* ieee style elementary float functions */
426 externC float __ieee754_sqrtf (float);
427 externC float __ieee754_acosf (float);
428 externC float __ieee754_acoshf (float);
429 externC float __ieee754_logf (float);
430 externC float __ieee754_atanhf (float);
431 externC float __ieee754_asinf (float);
432 externC float __ieee754_atan2f (float,float);
433 externC float __ieee754_expf (float);
434 externC float __ieee754_coshf (float);
435 externC float __ieee754_fmodf (float,float);
436 externC float __ieee754_powf (float,float);
437 externC float
438 __ieee754_lgammaf_r( float, int * );
439
440 externC float
441 __ieee754_gammaf_r( float, int * );
442
443 externC float
444 __ieee754_lgammaf( float );
445
446 externC float
447 __ieee754_gammaf( float );
448 externC float __ieee754_log10f (float);
449 externC float __ieee754_sinhf (float);
450 externC float __ieee754_hypotf (float,float);
451 externC float __ieee754_j0f (float);
452 externC float __ieee754_j1f (float);
453 externC float __ieee754_y0f (float);
454 externC float __ieee754_y1f (float);
455 externC float __ieee754_jnf (int,float);
456 externC float __ieee754_ynf (int,float);
457 externC float __ieee754_remainderf (float,float);
458 externC cyg_int32 __ieee754_rem_pio2f (float,float*);
459 #ifdef _SCALB_INT
460 externC float __ieee754_scalbf ((float,int));
461 #else
462 externC float __ieee754_scalbf (float,float);
463 #endif
464
465 /* float versions of fdlibm kernel functions */
466 externC float __kernel_standard_float( float, float, int );
467 externC float __kernel_sinf (float,float,int);
468 externC float __kernel_cosf (float,float);
469 externC float __kernel_tanf (float,float,int);
470 externC int __kernel_rem_pio2f (float*,float*,int,int,int,const cyg_int32*);
471
472 #ifdef _COMPLEX_H
473
474 /*
475 * Quoting from ISO/IEC 9899:TC2:
476 *
477 * 6.2.5.13 Types
478 * Each complex type has the same representation and alignment requirements as
479 * an array type containing exactly two elements of the corresponding real type;
480 * the first element is equal to the real part, and the second element to the
481 * imaginary part, of the complex number.
482 */
483 typedef union {
484 float complex z;
485 float parts[2];
486 } float_complex;
487
488 typedef union {
489 double complex z;
490 double parts[2];
491 } double_complex;
492
493 typedef union {
494 long double complex z;
495 long double parts[2];
496 } long_double_complex;
497
498 #define REAL_PART(z) ((z).parts[0])
499 #define IMAG_PART(z) ((z).parts[1])
500
501 #endif /* _COMPLEX_H */
502
503
292 #endif // ifdef CYGPKG_LIBM 504 #endif // ifdef CYGPKG_LIBM
293 505
294 #endif // CYGONCE_LIBM_MATHINCL_FDLIBM_H multiple inclusion protection 506 #endif // CYGONCE_LIBM_MATHINCL_FDLIBM_H multiple inclusion protection
295 507
296 // EOF fdlibm.h 508 // EOF fdlibm.h