home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The C Users' Group Library 1994 August
/
wc-cdrom-cusersgrouplibrary-1994-08.iso
/
listings
/
v_11_07
/
1107088a
< prev
next >
Wrap
Text File
|
1993-05-01
|
12KB
|
357 lines
/* REAL_T.H Listing 1 */
#if !defined ( REAL_T_INCLUDED )
#define REAL_T_INCLUDED
/* Minimum numbers before sqrt() fails */
#define FLT_SQRT_MIN 1.0e-19F
#define DBL_SQRT_MIN 1.0e-154
#define LDBL_SQRT_MIN 1.0e-2466L
#if defined ( REAL_FLT )
/* Type and constant macro for float */
typedef float real_t;
#define RC( x ) ( x##F )
/* float.h constants */
#define REAL_DIG FLT_DIG
#define REAL_EPSILON FLT_EPSILON
#define REAL_GUARD FLT_GUARD
#define REAL_MANT_DIG FLT_MANT_DIG
#define REAL_MAX FLT_MAX
#define REAL_MAX_10_EXP FLT_MAX_10_EXP
#define REAL_MAX_EXP FLT_MAX_EXP
#define REAL_MIN FLT_MIN
#define REAL_MIN_10_EXP FLT_MIN_10_EXP
#define REAL_MIN_EXP FLT_MIN_EXP
#define REAL_NORMALIZE FLT_NORMALIZE
#define REAL_RADIX FLT_RADIX
#define REAL_ROUNDS FLT_ROUNDS
#define REAL_SQRT_MIN FLT_SQRT_MIN
#if !defined ( REAL_MP )
#undef DBL_DIG
#undef DBL_EPSILON
#undef DBL_MANT_DIG
#undef DBL_MAX
#undef DBL_MAX_10_EXP
#undef DBL_MAX_EXP
#undef DBL_MIN
#undef DBL_MIN_10_EXP
#undef DBL_MIN_EXP
#undef DBL_RADIX
#undef DBL_ROUNDS
#undef DBL_SQRT_MIN
#undef LDBL_DIG
#undef LDBL_EPSILON
#undef LDBL_MANT_DIG
#undef LDBL_MAX
#undef LDBL_MAX_10_EXP
#undef LDBL_MAX_EXP
#undef LDBL_MIN
#undef LDBL_MIN_10_EXP
#undef LDBL_MIN_EXP
#undef LDBL_RADIX
#undef LDBL_ROUNDS
#undef LDBL_SQRT_MIN
#define DBL_DIG REAL_DIG
#define DBL_EPSILON REAL_EPSILON
#define DBL_MANT_DIG REAL_MANT_DIG
#define DBL_MAX REAL_MAX
#define DBL_MAX_10_EXP REAL_MAX_10_EXP
#define DBL_MAX_EXP REAL_MAX_EXP
#define DBL_MIN REAL_MIN
#define DBL_MIN_10_EXP REAL_MIN_10_EXP
#define DBL_MIN_EXP REAL_MIN_EXP
#define DBL_RADIX REAL_RADIX
#define DBL_ROUNDS REAL_ROUNDS
#define DBL_SQRT_MIN REAL_SQRT_MIN
#define LDBL_DIG REAL_DIG
#define LDBL_EPSILON REAL_EPSILON
#define LDBL_MANT_DIG REAL_MANT_DIG
#define LDBL_MAX REAL_MAX
#define LDBL_MAX_10_EXP REAL_MAX_10_EXP
#define LDBL_MAX_EXP REAL_MAX_EXP
#define LDBL_MIN REAL_MIN
#define LDBL_MIN_10_EXP REAL_MIN_10_EXP
#define LDBL_MIN_EXP REAL_MIN_EXP
#define LDBL_RADIX REAL_RADIX
#define LDBL_ROUNDS REAL_ROUNDS
#define LDBL_SQRT_MIN REAL_SQRT_MIN
typedef long double long_double;
#define long_double real_t
#define double real_t
#endif /* #if !defined ( REAL_MP ) */
/* math.h functions */
#define acos( x ) ( (float)acos( (double)(x) ) )
#define asin( x ) ( (float)asin( (double)(x) ) )
#define atan( x ) ( (float)atan( (double)(x) ) )
#define atan2( y, x ) ( (float)atan2( (double)(y), \
(double)(x) ) )
#define ceil( x ) ( (float)ceil( (double)(x) ) )
#define cos( x ) ( (float)cos( (double)(x) ) )
#define cosh( x ) ( (float)cosh( (double)(x) ) )
#define exp( x ) ( (float)exp( (double)(x) ) )
#define fabs( x ) ( (float)fabs( (double)(x) ) )
#define floor( x ) ( (float)floor( (double)(x) ) )
#define fmod( x, y ) ( (float)fmod( (double)(x), \
(double)(y) ) )
#define sin( x ) ( (float)sin( (double)(x) ) )
#define sinh( x ) ( (float)sinh( (double)(x) ) )
#define tan( x ) ( (float)tan( (double)(x) ) )
#define tanh( x ) ( (float)tanh( (double)(x) ) )
#if defined ( REAL_SAFE )
#define atof( x ) \
( ( (x) == NULL ) ? \
RC( 0.0 ) : (float)atof( (x) ) )
#define log( x ) \
( ( fabs( (x) ) ) < REAL_MIN ? \
(float)log( (double)REAL_MIN ) : \
(float)log( (double)fabs( (x) ) ) )
#define log10( x ) \
( ( fabs( x ) ) < REAL_MIN ? \
(float)log10( (double)REAL_MIN ) : \
(float)log10( (double)fabs( (x) ) ) )
#define pow( x, y ) \
( fabs( (y) ) < REAL_MIN ? \
RC( 1.0 ) : \
( fabs( (x) ) < REAL_MIN ? \
( (y) < RC( 0.0 ) ? \
REAL_MAX : RC( 0.0 ) ) : \
(float)pow( (double)(x), (double)(y) ) ) )
#define sqrt( x ) \
( fabs( (x) ) < REAL_SQRT_MIN ? \
RC( 0.0 ) : (float)sqrt( (double)fabs( (x) ) ) )
#else
#define atof( x ) ( (float)atof( (x) ) )
#define log( x ) ( (float)log( (double)(x) ) )
#define log10( x ) ( (float)log10( (double)(x) ) )
#define pow( x, y ) ( (float)pow( (double)(x), \
(double)(y) ) )
#define sqrt( x ) ( (float)sqrt( (double)(x) ) )
#endif /* #if defined ( REAL_SAFE ) */
#else
#if defined ( REAL_LDBL )
/* Type and constant macro for long double */
typedef long double real_t;
typedef long double long_double;
#define RC( x ) ( x##L )
/* float.h constants */
#define REAL_DIG LDBL_DIG
#define REAL_EPSILON LDBL_EPSILON
#define REAL_MANT_DIG LDBL_MANT_DIG
#define REAL_MAX LDBL_MAX
#define REAL_MAX_10_EXP LDBL_MAX_10_EXP
#define REAL_MAX_EXP LDBL_MAX_EXP
#define REAL_MIN LDBL_MIN
#define REAL_MIN_10_EXP LDBL_MIN_10_EXP
#define REAL_MIN_EXP LDBL_MIN_EXP
#define REAL_RADIX LDBL_RADIX
#define REAL_ROUNDS LDBL_ROUNDS
#define REAL_SQRT_MIN LDBL_SQRT_MIN
#if !defined ( REAL_MP )
#undef FLT_DIG
#undef FLT_EPSILON
#undef FLT_MANT_DIG
#undef FLT_MAX
#undef FLT_MAX_10_EXP
#undef FLT_MAX_EXP
#undef FLT_MIN
#undef FLT_MIN_10_EXP
#undef FLT_MIN_EXP
#undef FLT_RADIX
#undef FLT_ROUNDS
#undef FLT_SQRT_MIN
#undef DBL_DIG
#undef DBL_EPSILON
#undef DBL_MANT_DIG
#undef DBL_MAX
#undef DBL_MAX_10_EXP
#undef DBL_MAX_EXP
#undef DBL_MIN
#undef DBL_MIN_10_EXP
#undef DBL_MIN_EXP
#undef DBL_RADIX
#undef DBL_ROUNDS
#undef DBL_SQRT_MIN
#define DBL_DIG REAL_DIG
#define DBL_EPSILON REAL_EPSILON
#define DBL_MANT_DIG REAL_MANT_DIG
#define DBL_MAX REAL_MAX
#define DBL_MAX_10_EXP REAL_MAX_10_EXP
#define DBL_MAX_EXP REAL_MAX_EXP
#define DBL_MIN REAL_MIN
#define DBL_MIN_10_EXP REAL_MIN_10_EXP
#define DBL_MIN_EXP REAL_MIN_EXP
#define DBL_RADIX REAL_RADIX
#define DBL_ROUNDS REAL_ROUNDS
#define DBL_SQRT_MIN REAL_SQRT_MIN
#define FLT_DIG REAL_DIG
#define FLT_EPSILON REAL_EPSILON
#define FLT_MANT_DIG REAL_MANT_DIG
#define FLT_MAX REAL_MAX
#define FLT_MAX_10_EXP REAL_MAX_10_EXP
#define FLT_MAX_EXP REAL_MAX_EXP
#define FLT_MIN REAL_MIN
#define FLT_MIN_10_EXP REAL_MIN_10_EXP
#define FLT_MIN_EXP REAL_MIN_EXP
#define FLT_RADIX REAL_RADIX
#define FLT_ROUNDS REAL_ROUNDS
#define FLT_SQRT_MIN REAL_SQRT_MIN
#define float real_t
#define double real_t
#endif /* #if !defined ( REAL_MP ) */
/* math.h functions */
#define acos acosl
#define asin asinl
#define atan atanl
#define atan2 atan2l
#define ceil ceill
#define cos cosl
#define cosh coshl
#define exp expl
#define fabs fabsl
#define floor floorl
#define fmod fmodl
#define sin sinl
#define sinh sinhl
#define tan tanl
#define tanh tanhl
#if defined ( REAL_SAFE )
#define atof( x ) \
( ( (x) == NULL ) ? \
RC( 0.0 ) : (float)atofl( (x) ) )
#define log( x ) \
( ( fabsl( (x) ) ) < REAL_MIN ? \
logl( REAL_MIN ) : logl( fabsl( (x) ) ) )
#define log10( x ) \
( ( fabsl( x ) ) < REAL_MIN ? \
log10l( REAL_MIN ) : log10l( fabs( x ) ) )
#define pow( x, y ) \
( fabsl( (y) ) < REAL_MIN ? \
RC( 1.0 ) : \
( fabsl( (x) ) < REAL_MIN ? \
( (y) < RC( 0.0 ) ? \
REAL_MAX : RC( 0.0 ) ) : \
(float)powl( (x), (y) ) ) )
#define sqrt( x ) \
( fabsl( (x) ) < REAL_SQRT_MIN ? \
RC( 0.0 ) : sqrtl( fabsl( (x) ) ) )
#else
#define atof atofl
#define log logl
#define log10 log10l
#define pow powl
#define sqrt sqrtl
#endif /* #if defined ( REAL_SAFE ) */
#else /* REAL_DBL is default */
/* Type and constant macro for double */
typedef double real_t;
#define RC( x ) ( x )
/* float.h constants */
#define REAL_DIG DBL_DIG
#define REAL_EPSILON DBL_EPSILON
#define REAL_MANT_DIG DBL_MANT_DIG
#define REAL_MAX DBL_MAX
#define REAL_MAX_10_EXP DBL_MAX_10_EXP
#define REAL_MAX_EXP DBL_MAX_EXP
#define REAL_MIN DBL_MIN
#define REAL_MIN_10_EXP DBL_MIN_10_EXP
#define REAL_MIN_EXP DBL_MIN_EXP
#define REAL_RADIX DBL_RADIX
#define REAL_ROUNDS DBL_ROUNDS
#define REAL_SQRT_MIN DBL_SQRT_MIN
#if !defined ( REAL_MP )
#undef FLT_DIG
#undef FLT_EPSILON
#undef FLT_MANT_DIG
#undef FLT_MAX
#undef FLT_MAX_10_EXP
#undef FLT_MAX_EXP
#undef FLT_MIN
#undef FLT_MIN_10_EXP
#undef FLT_MIN_EXP
#undef FLT_RADIX
#undef FLT_ROUNDS
#undef FLT_SQRT_MIN
#undef LDBL_DIG
#undef LDBL_EPSILON
#undef LDBL_MANT_DIG
#undef LDBL_MAX
#undef LDBL_MAX_10_EXP
#undef LDBL_MAX_EXP
#undef LDBL_MIN
#undef LDBL_MIN_10_EXP
#undef LDBL_MIN_EXP
#undef LDBL_RADIX
#undef LDBL_ROUNDS
#undef LDBL_SQRT_MIN
#define FLT_DIG REAL_DIG
#define FLT_EPSILON REAL_EPSILON
#define FLT_MANT_DIG REAL_MANT_DIG
#define FLT_MAX REAL_MAX
#define FLT_MAX_10_EXP REAL_MAX_10_EXP
#define FLT_MAX_EXP REAL_MAX_EXP
#define FLT_MIN REAL_MIN
#define FLT_MIN_10_EXP REAL_MIN_10_EXP
#define FLT_MIN_EXP REAL_MIN_EXP
#define FLT_RADIX REAL_RADIX
#define FLT_ROUNDS REAL_ROUNDS
#define LDBL_DIG REAL_DIG
#define LDBL_EPSILON REAL_EPSILON
#define LDBL_MANT_DIG REAL_MANT_DIG
#define LDBL_MAX REAL_MAX
#define LDBL_MAX_10_EXP REAL_MAX_10_EXP
#define LDBL_MAX_EXP REAL_MAX_EXP
#define LDBL_MIN REAL_MIN
#define LDBL_MIN_10_EXP REAL_MIN_10_EXP
#define LDBL_MIN_EXP REAL_MIN_EXP
#define LDBL_RADIX REAL_RADIX
#define LDBL_ROUNDS REAL_ROUNDS
typedef long double long_double;
#define long_double real_t
#define float real_t
#endif /* #if !defined ( REAL_MP ) */
/* math.h functions */
#if defined ( REAL_SAFE )
#define atof( x ) \
( ( (x) == NULL ) ? \
RC( 0.0 ) : (float)atof( (x) ) )
#define log( x ) \
( ( fabs( (x) ) ) < REAL_MIN ? \
log( REAL_MIN ) : log( fabs( (x) ) ) )
#define log10( x ) \
( ( fabs( x ) ) < REAL_MIN ? \
log10( REAL_MIN ) : log10( fabs( x ) ) )
#define pow( x, y ) \
( fabs( (y) ) < REAL_MIN ? \
RC( 1.0 ) : \
( fabs( (x) ) < REAL_MIN ? \
( (y) < RC( 0.0 ) ? \
REAL_MAX : RC( 0.0 ) ) : \
(float)pow( (x), (y) ) ) )
#define sqrt( x ) \
( fabs( (x) ) < REAL_SQRT_MIN ? \
RC( 0.0 ) : sqrtl( fabs( (x) ) ) )
#endif /* #if defined ( REAL_SAFE ) */
#endif /* #if defined ( REAL_LDBL ) */
#endif /* #if defined ( REAL_FLT ) */
/* kludge for long double */
#if defined ( REAL_NL ) && !defined ( REAL_MP )
#define long
#endif
#endif /* #if defined ( REAL_T_INCLUDED ) */
/* End of REAL_T.H */