diff options
Diffstat (limited to 'newlib/libc/stdlib/strtod.c')
-rw-r--r-- | newlib/libc/stdlib/strtod.c | 49 |
1 files changed, 13 insertions, 36 deletions
diff --git a/newlib/libc/stdlib/strtod.c b/newlib/libc/stdlib/strtod.c index 9b70dfc3c..c16d75d4f 100644 --- a/newlib/libc/stdlib/strtod.c +++ b/newlib/libc/stdlib/strtod.c @@ -1,18 +1,18 @@ /* FUNCTION - <<strtod>>, <<strtof>>---string to double or float + <<strtod>>, <<strtodf>>---string to double or float INDEX strtod INDEX _strtod_r INDEX - strtof + strtodf ANSI_SYNOPSIS #include <stdlib.h> double strtod(const char *<[str]>, char **<[tail]>); - float strtof(const char *<[str]>, char **<[tail]>); + float strtodf(const char *<[str]>, char **<[tail]>); double _strtod_r(void *<[reent]>, const char *<[str]>, char **<[tail]>); @@ -23,7 +23,7 @@ TRAD_SYNOPSIS char *<[str]>; char **<[tail]>; - float strtof(<[str]>,<[tail]>) + float strtodf(<[str]>,<[tail]>) char *<[str]>; char **<[tail]>; @@ -48,7 +48,7 @@ DESCRIPTION (which will contain at least the terminating null character of <[str]>) is stored in <<*<[tail]>>>. If you want no assignment to <<*<[tail]>>>, pass a null pointer as <[tail]>. - <<strtof>> is identical to <<strtod>> except for its return type. + <<strtodf>> is identical to <<strtod>> except for its return type. This implementation returns the nearest machine number to the input decimal string. Ties are broken by using the IEEE @@ -111,16 +111,15 @@ _DEFUN (_strtod_r, (ptr, s00, se), int bb2, bb5, bbe, bd2, bd5, bbbits, bs2, c, dsign, e1, esign, i, j, k, nd, nd0, nf, nz, nz0, sign; long e; - _CONST char *s, *s0, *s1, *s2; + _CONST char *s, *s0, *s1; double aadj, aadj1, adj; long L; unsigned long z; __ULong y; union double_union rv, rv0; - int nanflag; _Bigint *bb, *bb1, *bd, *bd0, *bs, *delta; - sign = nz0 = nz = nanflag = 0; + sign = nz0 = nz = 0; rv.d = 0.; for (s = s00;; s++) switch (*s) @@ -146,23 +145,7 @@ _DEFUN (_strtod_r, (ptr, s00, se), goto break2; } break2: - 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') + if (*s == '0') { nz0 = 1; while (*++s == '0'); @@ -222,7 +205,7 @@ dig_done: s = s00; goto ret; } - s2 = s; + s00 = s; esign = 0; switch (c = *++s) { @@ -253,7 +236,7 @@ dig_done: e = 0; } else - s = s2; + s = s00; } if (!nd) { @@ -725,10 +708,7 @@ retfree: ret: if (se) *se = (char *) s; - - if (nanflag) - return nan (NULL); - return (sign && (s != s00)) ? -rv.d : rv.d; + return sign ? -rv.d : rv.d; } #ifndef NO_REENT @@ -741,14 +721,11 @@ _DEFUN (strtod, (s00, se), } float -_DEFUN (strtof, (s00, se), +_DEFUN (strtodf, (s00, se), _CONST char *s00 _AND char **se) { - double retval = _strtod_r (_REENT, s00, se); - if (isnan (retval)) - return nanf (NULL); - return (float)retval; + return _strtod_r (_REENT, s00, se); } #endif |