diff options
author | Eric Andersen <andersen@codepoet.org> | 2002-05-09 08:15:21 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2002-05-09 08:15:21 +0000 |
commit | 3942feca80e3b0f55f0f27004e05316d03d1dbe4 (patch) | |
tree | 8921ebdce7af20a18952a01566e8ad36c5a1daec /libm | |
parent | e4071b93db0e2fd4aa3b678a6188da2de1c8eb2f (diff) |
Fill a few little holes in the math library
Diffstat (limited to 'libm')
-rw-r--r-- | libm/Makefile | 2 | ||||
-rw-r--r-- | libm/fpmacros.c | 108 | ||||
-rw-r--r-- | libm/nan.c | 48 |
3 files changed, 112 insertions, 46 deletions
diff --git a/libm/Makefile b/libm/Makefile index b0821c82a..80ee30c4d 100644 --- a/libm/Makefile +++ b/libm/Makefile @@ -62,7 +62,7 @@ CSRC = e_acos.c e_acosh.c e_asin.c e_atan2.c e_atanh.c e_cosh.c\ w_cosh.c w_drem.c w_exp.c w_fmod.c w_gamma.c w_gamma_r.c\ w_hypot.c w_j0.c w_j1.c w_jn.c w_lgamma.c w_lgamma_r.c\ w_log.c w_log10.c w_pow.c w_remainder.c w_scalb.c w_sinh.c\ - w_sqrt.c w_sqrtf.c fpmacros.c + w_sqrt.c w_sqrtf.c fpmacros.c nan.c else # This list of math functions was taken from POSIX/IEEE 1003.1b-1993 CSRC = w_acos.c w_asin.c s_atan.c w_atan2.c s_ceil.c s_cos.c \ diff --git a/libm/fpmacros.c b/libm/fpmacros.c index a9f63df4b..3dbc8a13c 100644 --- a/libm/fpmacros.c +++ b/libm/fpmacros.c @@ -15,8 +15,8 @@ ** ** Change History (most recent first): ** -** 07 Jul 01 ram First created from fpfloatfunc.c, fp.c, -** classify.c and sign.c in MathLib v3 Mac OS9. +** 07 Jul 01 ram First created from fpfloatfunc.c, fp.c, +** classify.c and sign.c in MathLib v3 Mac OS9. ** ***********************************************************************/ @@ -148,7 +148,7 @@ long int __isnorma ( double x ) Calls: none ***********************************************************************/ -long int __isfinitef ( float x ) +long int __finitef ( float x ) { union { unsigned long int lval; @@ -159,13 +159,56 @@ long int __isfinitef ( float x ) return ((z.lval & FEXP_MASK) != FEXP_MASK); } -long int __isfinite ( double x ) +long int __finite ( double x ) { return ( __fpclassify ( x ) >= FP_ZERO ); } /*********************************************************************** + long int __signbitf(float x) returns nonzero if and only if the sign + bit of x is set and zero otherwise. + + Exceptions: INVALID is raised if x is a signaling NaN. + + Calls: none +***********************************************************************/ + +long int __signbitf ( float x ) +{ + union { + unsigned long int lval; + float fval; + } z; + + z.fval = x; + return ((z.lval & SIGN_MASK) != 0); +} + + +/*********************************************************************** + Function sign of a double. + Implementation of sign bit for the PowerPC. + + Calls: none +***********************************************************************/ + +long int __signbit ( double arg ) +{ + union + { + dHexParts hex; + double dbl; + } x; + long int sign; + + x.dbl = arg; + sign = ( ( x.hex.high & dSgnMask ) == dSgnMask ) ? 1 : 0; + return sign; +} + + +/*********************************************************************** * long int __isinff(float x) returns -1 if value represents negative * infinity, 1 if value represents positive infinity, * and 0 otherwise. @@ -190,6 +233,17 @@ long int __isinf ( double x ) return 0; } +#if 0 +long int __isinfl ( long double x ) +{ + long int class = __fpclassify(x); + if ( class == FP_INFINITE ) { + return ( (__signbit(x)) ? -1 : 1); + } + return 0; +} +#endif + /*********************************************************************** long int __isnanf(float x) returns nonzero if and only if x is a NaN and zero otherwise. @@ -217,47 +271,11 @@ long int __isnan ( double x ) return ( ( class == FP_SNAN ) || ( class == FP_QNAN ) ); } - -/*********************************************************************** - long int __signbitf(float x) returns nonzero if and only if the sign - bit of x is set and zero otherwise. - - Exceptions: INVALID is raised if x is a signaling NaN. - - Calls: none -***********************************************************************/ - -long int __signbitf ( float x ) -{ - union { - unsigned long int lval; - float fval; - } z; - - z.fval = x; - return ((z.lval & SIGN_MASK) != 0); -} - - -/*********************************************************************** - Function sign of a double. - Implementation of sign bit for the PowerPC. - - Calls: none -***********************************************************************/ - -long int __signbit ( double arg ) +#if 0 +long int __isnanl ( long double x ) { - union - { - dHexParts hex; - double dbl; - } x; - long int sign; - - x.dbl = arg; - sign = ( ( x.hex.high & dSgnMask ) == dSgnMask ) ? 1 : 0; - return sign; + long int class = __fpclassify(x); + return ( ( class == FP_SNAN ) || ( class == FP_QNAN ) ); } - +#endif diff --git a/libm/nan.c b/libm/nan.c new file mode 100644 index 000000000..8d7998896 --- /dev/null +++ b/libm/nan.c @@ -0,0 +1,48 @@ +/*********************************************************************** + nan, nanf, nanl - return quiet NaN + + These functions shall return a quiet NaN, if available, with content + indicated through tagp. + + If the implementation does not support quiet NaNs, these functions + shall return zero. + + Calls: strlen(), sprintf(), strtod() + +***********************************************************************/ +#include <math.h> +#include <string.h> +#include <stdlib.h> +#include <stdio.h> + +double nan (const char *tagp) +{ + if (tagp[0] != '\0') { + char buf[6 + strlen (tagp)]; + sprintf (buf, "NAN(%s)", tagp); + return strtod (buf, NULL); + } + return NAN; +} + +float nanf (const char *tagp) +{ + if (tagp[0] != '\0') { + char buf[6 + strlen (tagp)]; + sprintf (buf, "NAN(%s)", tagp); + return strtof (buf, NULL); + } + return NAN; +} + +#if 0 +long double nanl (const char *tagp) +{ + if (tagp[0] != '\0') { + char buf[6 + strlen (tagp)]; + sprintf (buf, "NAN(%s)", tagp); + return strtold (buf, NULL); + } + return NAN; +} +#endif |