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/nan.c | |
parent | e4071b93db0e2fd4aa3b678a6188da2de1c8eb2f (diff) |
Fill a few little holes in the math library
Diffstat (limited to 'libm/nan.c')
-rw-r--r-- | libm/nan.c | 48 |
1 files changed, 48 insertions, 0 deletions
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 |