summaryrefslogtreecommitdiff
path: root/libkern/strtod.c
diff options
context:
space:
mode:
Diffstat (limited to 'libkern/strtod.c')
-rw-r--r--libkern/strtod.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/libkern/strtod.c b/libkern/strtod.c
new file mode 100644
index 00000000..c591e44c
--- /dev/null
+++ b/libkern/strtod.c
@@ -0,0 +1,31 @@
+#include <lib9.h>
+
+static int
+strtodf(void *vp)
+{
+ return *(*((char**)vp))++;
+}
+
+double
+strtod(char *s, char **end)
+{
+ double d;
+ char *ss;
+ int c;
+
+ ss = s;
+ d = charstod(strtodf, &s);
+ /*
+ * Fix cases like 2.3e+ , which charstod will consume
+ */
+ if(end){
+ *end = --s;
+ while(s > ss){
+ c = *--s;
+ if(c!='-' && c!='+' && c!='e' && c!='E')
+ break;
+ (*end)--;
+ }
+ }
+ return d;
+}