code: 9ferno

ref: 6dce09cec3bf6a689fa9a3f838df67d7d48d9d1a
dir: /libkern/strtod.c/

View raw version
#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;
}