2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
5 ANSI C function strtod().
14 /*****************************************************************************
27 Convert a string of digits into a double.
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
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
51 atof(), atoi(), atol(), strtol(), strtoul()
55 ******************************************************************************/
57 double val
= 0, precision
;
61 /* skip all leading spaces */
62 while (isspace (*str
))
65 /* start with scanning the floting point number */
68 /* Is there a sign? */
69 if (*str
== '+' || *str
== '-')
72 /* scan numbers before the dot */
75 val
= val
* 10 + (*str
- '0');
79 /* see if there is the dot */
83 /* scan the numbers behind the dot */
85 while (isdigit (*str
))
87 val
+= ((*str
- '0') * precision
) ;
89 precision
= precision
* 0.1;
93 /* look for a sequence like "E+10" or "e-22" */
94 if(tolower(*str
) == 'e')
98 if (*str
== '+' || *str
== '-')
101 while (isdigit (*str
))
103 exp
= exp
* 10 + (*str
- '0');
108 val
*= pow (10, exp
);
116 *endptr
= (char *)str
;
123 void strtod (const char * str
,char ** endptr
)
128 #endif /* AROS_NOFPU */