h15724
s 00096/00000/00000
d D 1.1 82/08/03 08:41:07 cecily 1 0
e
u
U
t
T
I 1
/*
	C library - ascii to floating
*/

#include <math.h>
#include <ctype.h>

double
atof(p)
register char *p;
{
	register c;
	double fl, flexp, exp10;
	double big = 72057594037927936.;  /*2^56*/
	double ldexp();
	int nd;
	register eexp, exp, neg, negexp, bexp;

	neg = 1;
	while((c = *p++) == ' ')
		;
	if (c == '-')
		neg = -1;
	else if (c=='+')
		;
	else
		--p;

	exp = 0;
	fl = 0;
	nd = 0;
	while ((c = *p++), isdigit(c)) {
		if (fl<big)
			fl = 10*fl + (c-'0');
		else
			exp++;
		nd++;
	}

	if (c == '.') {
		while ((c = *p++), isdigit(c)) {
			if (fl<big) {
				fl = 10*fl + (c-'0');
				exp--;
			}
		nd++;
		}
	}

	negexp = 1;
	eexp = 0;
	if ((c == 'E') || (c == 'e')) {
		if ((c= *p++) == '+')
			;
		else if (c=='-')
			negexp = -1;
		else
			--p;

		while ((c = *p++), isdigit(c)) {
			eexp = 10*eexp+(c-'0');
		}
		if (negexp<0)
			eexp = -eexp;
		exp = exp + eexp;
	}

	negexp = 1;
	if (exp<0) {
		negexp = -1;
		exp = -exp;
	}


	if((nd+exp*negexp) < -LOGHUGE){
		fl = 0;
		exp = 0;
	}
	flexp = 1;
	exp10 = 10;
	for (;;) {
		if (exp&01)
			flexp *= exp10;
		exp >>= 1;
		if (exp==0)
			break;
		exp10 *= exp10;
	}
	if (negexp<0)
		fl /= flexp;
	else
		fl *= flexp;
	if (neg<0)
		fl = -fl;
	return(fl);
}
E 1
