7double atof(
const char* nptr)
10 double fraction = 0.0;
13 bool isNegative =
false;
14 bool hasExponent =
false;
15 bool isExponentNegative =
false;
17 while (
isspace((
unsigned char)*nptr))
26 else if (*nptr ==
'-')
32 while (*nptr >=
'0' && *nptr <=
'9')
34 result = result * 10.0 + (*nptr -
'0');
42 while (*nptr >=
'0' && *nptr <=
'9')
44 fraction = fraction * 10.0 + (*nptr -
'0');
49 result += fraction / divisor;
52 if (*nptr ==
'e' || *nptr ==
'E')
61 else if (*nptr ==
'-')
64 isExponentNegative =
true;
67 while (*nptr >=
'0' && *nptr <=
'9')
69 exponent = exponent * 10 + (*nptr -
'0');
77 for (
int i = 0; i < exponent; i++)
82 if (isExponentNegative)
92 return isNegative ? -result : result;