1 #ifndef CNOID_UTIL_STRTOF_H
2 #define CNOID_UTIL_STRTOF_H
16 inline float strtof(
const char* nptr,
char** endptr){
19 inline double strtod(
const char* nptr,
char** endptr){
25 template<
typename T> T strtofloat(
const char* nptr,
char** endptr)
27 const char* org = nptr;
34 }
else if(*nptr ==
'-'){
38 if(isdigit((
unsigned char)*nptr)){
41 value = value * 10.0 + (*nptr -
'0');
43 }
while(isdigit((
unsigned char)*nptr));
48 if(isdigit((
unsigned char)*nptr)){
52 value += small * (*nptr -
'0');
55 }
while(isdigit((
unsigned char)*nptr));
58 if(valid && (*nptr ==
'e' || *nptr ==
'E')){
64 }
else if(*nptr ==
'-'){
68 if(isdigit((
unsigned char)*nptr)){
72 p = p * 10.0 + (*nptr -
'0');
74 }
while(isdigit((
unsigned char)*nptr));
75 value *= pow(10.0, (
double)(psign * p));
79 *endptr = (
char*)nptr;
85 inline float strtof(
const char* nptr,
char** endptr) {
86 return strtofloat<float>(nptr, endptr);
88 inline double strtod(
const char* nptr,
char** endptr) {
89 return strtofloat<double>(nptr, endptr);