Article View: comp.sys.atari.st
Article #2324Enhancements for GCC library for Atari ST
From: Piet van Oostrum
Date: Tue, 11 Jul 1989 15:36
Date: Tue, 11 Jul 1989 15:36
82 lines
2321 bytes
2321 bytes
The Atari GCC compiler does not properly deal with floating point numbers
with exponents (like 1E10). This is becuase the standard library's atof
does not like them. I just put it in there. Here is the new routine:
/* jrd's kludgy atof */
/* It is much less kludgy now -- Piet van Oostrum (piet@cs.ruu.nl) */
/* July 11, 1989 */
#include <ctype.h>
#define maybe_negate(num,flg) ((flg) ? -(num) : (num))
double atof(str)
char * str;
{
int neg = 0;
double accum, factor, ten = 10.0;
char c;
while (isspace(*str)) str++;
if (*str == '-')
{
neg = 1;
str++;
}
else if (*str == '+') str++;
accum = 0;
for ( ; ((c = *str++) && (isdigit(c))) ; )
{
accum = accum * ten + (c - '0');
}
if (c == '.')
{
double tenth = 0.1;
factor = tenth;
for ( ; ((c = *str++) && (isdigit(c))) ; )
{
accum = accum + ((c - '0') * factor);
factor = factor * tenth;
}
}
if (c == 'e' || c == 'E')
{
register int negexp = 0, exp = 0;
while (isspace(*str)) str++ ;
if (*str == '-')
{
negexp = 1;
str++;
}
else if (*str == '+') str++;
for ( ; ((c = *str++) && (isdigit(c))) ; )
{
exp = exp * 10 + c - '0';
}
factor = 1.0;
for ( ; exp >= 10; exp -= 10)
factor *= 10000000000.0;
for ( ; exp > 0; exp--)
factor *= ten;
if (negexp)
accum /= factor;
else
accum *= factor;
}
return(maybe_negate(accum,neg));
}
--
Piet van Oostrum, Dept of Computer Science, University of Utrecht
Padualaan 14, P.O. Box 80.089, 3508 TB Utrecht, The Netherlands
Telephone: +31-30-531806. piet@cs.ruu.nl (mcvax!hp4nl!ruuinf!piet)
Technical Details
Message-ID:
<1444@ruuinf.cs.ruu.nl>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!wasatch!cs.utexas.edu!uunet!mcvax!hp4nl!ruuinf!pietReferences:
<1443@ruuinf.cs.ruu.nl>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!wasatch!cs.utexas.edu!uunet!mcvax!hp4nl!ruuinf!piet From: piet@cs.ruu.nl (Piet van Oostrum) Newsgroups: comp.sys.atari.st Subject: Enhancements for GCC library for Atari ST Message-ID: <1444@ruuinf.cs.ruu.nl> Date: 11 Jul 89 15:36:56 GMT References: <1443@ruuinf.cs.ruu.nl> Sender: news@ruuinf.cs.ruu.nl Reply-To: piet@cs.ruu.nl (Piet van Oostrum) Followup-To: comp.sys.atari.st Organization: Dept of Computer Science, University of Utrecht, Holland Lines: 82 In-reply-to: piet@cs.ruu.nl (Piet van Oostrum)