3 * - By John Hodge (thePowersGang)
6 * - strto[df]/atof implimentation
12 #include <stdlib.h> // strtoll
14 double strtod(const char *ptr, char **end)
21 while( isspace(*ptr) )
24 if( *ptr == '+' || *ptr == '-' )
26 negative = (*ptr == '-');
32 if( strncasecmp(ptr, "NAN", 3) == 0)
35 while( isalnum(*ptr) || *ptr == '_' )
38 rv = negative ? -NAN : NAN;
44 if( strncasecmp(ptr, "INF", 3) == 0 )
46 if( strncasecmp(ptr, "INFINITY", 8) == 0 )
50 rv = negative ? -INFINITY : INFINITY;
56 if( *ptr == '0' && (ptr[1] == 'X' || ptr[1] == 'x') )
62 rv = strtoll(ptr, &tmp, (is_hex ? 16 : 10));
70 if( isspace(*ptr) || *ptr == '-' || *ptr == '+' ) {
73 double frac = strtoll(ptr, &tmp, (is_hex ? 16 : 10));
86 if( *ptr == 'P' || *ptr == 'p' )
89 exp = strtoll(ptr, &tmp, 16);
95 if( *ptr == 'E' || *ptr == 'e' )
98 exp = strtoll(ptr, &tmp, 10);
126 float strtof(const char *ptr, char **end)
128 double rv = strtod(ptr, end);
133 float atof(const char *ptr)
135 return strtof(ptr, NULL);