/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1985-2011 AT&T Intellectual Property *
* and is licensed under the *
* Common Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* David Korn <dgk@research.att.com> *
* Phong Vo <kpv@research.att.com> *
* *
***********************************************************************/
#include "sfhdr.h"
/* Convert a Sfdouble_t value represented in an ASCII format into
** the internal Sfdouble_t representation.
**
** Written by Kiem-Phong Vo.
*/
#if __STD_C
#else
static Sfdouble_t sfpow10(n)
reg int n;
#endif
{
switch(n)
{ case -3: return .001;
case -2: return .01;
case -1: return .1;
case 0: return 1.;
case 1: return 10.;
case 2: return 100.;
case 3: return 1000.;
}
if(n < 0)
{ dval = .0001;
for(n += 4; n < 0; n += 1)
dval /= 10.;
}
else
{ dval = 10000.;
for(n -= 4; n > 0; n -= 1)
dval *= 10.;
}
return dval;
}
#if __STD_C
#else
reg char* s; /* string to convert */
char** retp; /* to return the remainder of string */
#endif
{
reg int n, c, m;
#if _lib_locale
int decpoint = 0;
int thousand = 0;
#else
#endif
/* skip initial blanks */
while(isspace(*s))
++s;
/* get the sign */
s += 1;
dval = 0.;
while(*s)
{ /* accumulate a handful of the digits */
for(m = BATCH, n = 0; m > 0; --m, ++s)
{ /* get and process a char */
c = *s;
if(isdigit(c))
n = 10*n + (c - '0');
else break;
}
/* number of digits accumulated */
m = BATCH-m;
{ /* doing the integer part */
if(dval == 0.)
dval = (Sfdouble_t)n;
}
{ /* doing the fractional part */
fexp -= m;
if(n > 0)
}
else if(n)
{ /* doing the exponent part */
if(expsign)
n = -n;
}
if(!c)
break;
if(m < BATCH)
{ /* detected a non-digit */
if(c == decpoint)
{ /* start the fractional part or no match */
break;
s += 1;
}
else if(c == 'e' || c == 'E')
break;
c = *++s;
s += 1;
}
else break;
}
}
if(retp)
*retp = (char*)s;
}