Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Johnston <jjohnstn@redhat.com>2005-01-07 02:31:56 +0300
committerJeff Johnston <jjohnstn@redhat.com>2005-01-07 02:31:56 +0300
commit8fa6cb9a5d5c6e380985cb12b1a799ed3acc8f25 (patch)
treea9fdbccd90a418b7db29c7952343ad0c011f87b3 /newlib/libc/stdlib
parent69008322efa3e4b0b844cb552719801bef3be583 (diff)
2005-01-06 Jeff Johnston <jjohnstn@redhat.com>
* libc/stdlib/strtod.c (_strtod_r): Add NaN support. * (strtof): Ditto. * libc/stdio/vfscanf.c (__svfscanf_r): Ditto. * Makefile.am (MATHOBJS_IN_LIBC): Add s_nan and sf_nan functions for use by strtod and strtof. * Makefile.in: Regenerated.
Diffstat (limited to 'newlib/libc/stdlib')
-rw-r--r--newlib/libc/stdlib/strtod.c31
1 files changed, 27 insertions, 4 deletions
diff --git a/newlib/libc/stdlib/strtod.c b/newlib/libc/stdlib/strtod.c
index 19467f495..455389d02 100644
--- a/newlib/libc/stdlib/strtod.c
+++ b/newlib/libc/stdlib/strtod.c
@@ -117,9 +117,10 @@ _DEFUN (_strtod_r, (ptr, s00, se),
unsigned long z;
__ULong y;
union double_union rv, rv0;
+ int nanflag;
_Bigint *bb, *bb1, *bd, *bd0, *bs, *delta;
- sign = nz0 = nz = 0;
+ sign = nz0 = nz = nanflag = 0;
rv.d = 0.;
for (s = s00;; s++)
switch (*s)
@@ -145,7 +146,23 @@ _DEFUN (_strtod_r, (ptr, s00, se),
goto break2;
}
break2:
- if (*s == '0')
+ if (*s == 'n' || *s == 'N')
+ {
+ ++s;
+ if (*s == 'a' || *s == 'A')
+ {
+ ++s;
+ if (*s == 'n' || *s == 'N')
+ {
+ nanflag = 1;
+ ++s;
+ goto ret;
+ }
+ }
+ s = s00;
+ goto ret;
+ }
+ else if (*s == '0')
{
nz0 = 1;
while (*++s == '0');
@@ -708,7 +725,10 @@ retfree:
ret:
if (se)
*se = (char *) s;
- return sign ? -rv.d : rv.d;
+
+ if (nanflag)
+ return nan (NULL);
+ return (sign && (s != s00)) ? -rv.d : rv.d;
}
#ifndef NO_REENT
@@ -725,7 +745,10 @@ _DEFUN (strtof, (s00, se),
_CONST char *s00 _AND
char **se)
{
- return (float)_strtod_r (_REENT, s00, se);
+ double retval = _strtod_r (_REENT, s00, se);
+ if (isnan (retval))
+ return nanf (NULL);
+ return (float)retval;
}
#endif