xref: /inferno-os/libkern/strtod.c (revision b43c1ca5eb5fc65b93ae935a568432712797b049)
1 #include <lib9.h>
2 
3 static int
4 strtodf(void *vp)
5 {
6 	return *(*((char**)vp))++;
7 }
8 
9 double
10 strtod(char *s, char **end)
11 {
12 	double d;
13 	char *ss;
14 	int c;
15 
16 	ss = s;
17 	d = charstod(strtodf, &s);
18 	/*
19 	 * Fix cases like 2.3e+ , which charstod will consume
20 	 */
21 	if(end){
22 		*end = --s;
23 		while(s > ss){
24 			c = *--s;
25 			if(c!='-' && c!='+' && c!='e' && c!='E')
26 				break;
27 			(*end)--;
28 		}
29 	}
30 	return d;
31 }
32