Documented the fact that NAN is not handled by strtod.
[AROS.git] / compiler / clib / strtod.c
blob1c3233db548d1975cf4fccb11ec695c27d3700a1
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 ANSI C function strtod().
6 */
8 #ifndef AROS_NOFPU
10 #include <ctype.h>
11 #include <errno.h>
12 #include <limits.h>
14 /*****************************************************************************
16 NAME */
17 #include <stdlib.h>
18 #include <math.h>
20 double strtod (
22 /* SYNOPSIS */
23 const char * str,
24 char ** endptr)
26 /* FUNCTION
27 Convert a string of digits into a double.
29 INPUTS
30 str - The string which should be converted. Leading
31 whitespace are ignored. The number may be prefixed
32 by a '+' or '-'. An 'e' or 'E' introduces the exponent.
33 Komma is only allowed before exponent.
34 endptr - If this is non-NULL, then the address of the first
35 character after the number in the string is stored
36 here.
38 RESULT
39 The value of the string. The first character after the number
40 is returned in *endptr, if endptr is non-NULL. If no digits can
41 be converted, *endptr contains str (if non-NULL) and 0 is
42 returned.
44 NOTES
46 EXAMPLE
48 BUGS
49 NAN is not handled at the moment
51 SEE ALSO
52 atof(), atoi(), atol(), strtol(), strtoul()
54 INTERNALS
56 ******************************************************************************/
58 #warning TODO: implement NAN handling
59 double val = 0, precision;
60 int exp = 0;
61 char c = 0, c2 = 0;
63 /* skip all leading spaces */
64 while (isspace (*str))
65 str ++;
67 /* start with scanning the floting point number */
68 if (*str)
70 /* Is there a sign? */
71 if (*str == '+' || *str == '-')
72 c = *str ++;
74 /* scan numbers before the dot */
75 while (isdigit(*str))
77 val = val * 10 + (*str - '0');
78 str ++;
81 /* see if there is the dot */
82 if(*str == '.')
84 str++;
85 /* scan the numbers behind the dot */
86 precision = 0.1;
87 while (isdigit (*str))
89 val += ((*str - '0') * precision) ;
90 str ++;
91 precision = precision * 0.1;
95 /* look for a sequence like "E+10" or "e-22" */
96 if(tolower(*str) == 'e')
98 str++;
100 if (*str == '+' || *str == '-')
101 c2 = *str ++;
103 while (isdigit (*str))
105 exp = exp * 10 + (*str - '0');
106 str ++;
108 if (c2 == '-')
109 exp = -exp;
110 val *= pow (10, exp);
113 if (c == '-')
114 val = -val;
117 if (endptr)
118 *endptr = (char *)str;
120 return val;
121 } /* strtod */
123 #else
125 void strtod (const char * str,char ** endptr)
127 return;
130 #endif /* AROS_NOFPU */