5 * Reads a floating-point number by interpreting successive characters
6 * returned by (*f)(vp). The last call it makes to f terminates the
7 * scan, so is not a character in the number. It may therefore be
8 * necessary to back up the input stream up one byte after calling charstod.
11 #define ADVANCE *s++ = c; if(s>=e) return NaN(); c = (*f)(vp)
14 charstod(int(*f)(void*), void *vp)
16 char str[400], *s, *e, *start;
20 e = str + sizeof str - 1;
22 while(c == ' ' || c == '\t')
24 if(c == '-' || c == '+'){
28 while(c >= '0' && c <= '9'){
33 while(c >= '0' && c <= '9'){
37 if(s > start && (c == 'e' || c == 'E')){
39 if(c == '-' || c == '+'){
42 while(c >= '0' && c <= '9'){
45 }else if(s == start && (c == 'i' || c == 'I')){
47 if(c != 'n' && c != 'N')
50 if(c != 'f' && c != 'F')
53 if(c != 'i' && c != 'I')
56 if(c != 'n' && c != 'N')
59 if(c != 'i' && c != 'I')
62 if(c != 't' && c != 'T')
65 if(c != 'y' && c != 'Y')
67 ADVANCE; /* so caller can back up uniformly */
69 }else if(s == str && (c == 'n' || c == 'N')){
71 if(c != 'a' && c != 'A')
74 if(c != 'n' && c != 'N')
76 ADVANCE; /* so caller can back up uniformly */
80 return strtod(str, &s);