* clib atof() question
@ 1993-10-14 4:36 Bill Baines
1993-10-14 13:06 ` Bob Doherty
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Bill Baines @ 1993-10-14 4:36 UTC (permalink / raw)
I was porting a program called SatTrack from Sun to neXT and VAX/VMS in
preparation for tracking the shuttle STS-58 due to launch on Thursday.
The program was written by Manfred Bester, (DL5KR) is excellent, and works
well on the Sun platforms I have run it on.
On the NeXT, I ran into som problems. The satellite orbital data is
read from ascii files which are parsed up calculated upon by SatTrack. One
function makes extensive use of atof(). Return values from that function
are wild -- beyond anything that could be called round-off error.
I am not a great c programmer, so I wrote a little test program to validate my
understanding ot atof(). The outputs on various systems is below the source.
--------------------
#include <math.h>
int main()
{
double f1;
char *s1 = "1234.567";
f1 = atof(s1);
printf("%s, %f\n",s1, f1);
}
--------------------
1) On SunOS 4.?
1234.567, 1234.567000 [OK!]
2) On NeXTOS 3.0
1234.567, 1083394628.000000 [Not ok]
3) Silicon Graphics IRIX 4.?
1234.567, 1234.567000 [OK!]
4) VAX/VMS
(D_FLOAT)
1234.567, 1378108826.000000 [Not ok]
(G_FLOAT)
1234.567, 1245986995.000000 [Not ok]
So, Sun and SGI seem to work while Next and VMS don't. Have I left something
out here? Compiler switches?
Ideas appreciated.
--
Bill Baines, Operations and Tech. Support,
Simon Fraser University, Vancouver, British Columbia, Canada
bill@sfu.ca, (604) 291-3955, (fax 291-4242), VE7FML
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: clib atof() question
1993-10-14 4:36 clib atof() question Bill Baines
@ 1993-10-14 13:06 ` Bob Doherty
1993-10-14 13:18 ` Ken Cowan
1993-10-15 0:32 ` clib atof() question resolved... Thanks!!! Bill Baines
2 siblings, 0 replies; 4+ messages in thread
From: Bob Doherty @ 1993-10-14 13:06 UTC (permalink / raw)
In article <1993Oct14.043648.1611@sfu.ca>, bill@sfu.ca (Bill Baines) writes:
[snip, snip]
> --------------------
> #include <math.h>
> int main()
> {
> double f1;
> char *s1 = "1234.567";
>
> f1 = atof(s1);
> printf("%s, %f\n",s1, f1);
> }
> --------------------
[snip, snip]
> So, Sun and SGI seem to work while Next and VMS don't. Have I left something
> out here? Compiler switches?
>
The problem is that the atof prototype is specified by the ANSI standard
to be in stdlib.h, not math.h. Even though VAX/VMS C is not an ANSI C
compiler, the atof prototype is in stdlib.h. The same situation obtains
for Next, apparently. It appears as if SunOS and IRIX get it wrong.
With the change in the included file to stdlib.h, under VAX/VMS C and
gcc under VMS, the above program produces the same output as SunOS and
IRIX.
--
*********************************************************************
* Bob Doherty * Beltsville Human Nutrition Research Center *
* B161 R216A * EMAIL: doherty@bhnrc.usda.gov *
* BARC-East * doherty@Eisner.DECUS.Org *
* Beltsville, MD 20705 * bob.doherty@his.com *
* (301)-504-8147 * *
*********************************************************************
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: clib atof() question
1993-10-14 4:36 clib atof() question Bill Baines
1993-10-14 13:06 ` Bob Doherty
@ 1993-10-14 13:18 ` Ken Cowan
1993-10-15 0:32 ` clib atof() question resolved... Thanks!!! Bill Baines
2 siblings, 0 replies; 4+ messages in thread
From: Ken Cowan @ 1993-10-14 13:18 UTC (permalink / raw)
In article <1993Oct14.043648.1611@sfu.ca>, bill@sfu.ca (Bill Baines) writes:
|>Newsgroups: comp.lang.c,comp.sys.next.bugs,comp.sys.dec
|>Path: jac.nuo.dec.com!crl.dec.com!crl.dec.com!caen!usenet.cis.ufl.edu!usenet.ufl.edu!darwin.sura.net!howland.reston.ans.net!sol.ctr.columbia.edu!destroyer!nntp.cs.ubc.ca!newsserver.sfu.ca!news
|>From: bill@sfu.ca (Bill Baines)
|>Subject: clib atof() question
|>Message-ID: <1993Oct14.043648.1611@sfu.ca>
|>Keywords: atof
|>Sender: news@sfu.ca
|>Reply-To: bill@sfu.ca
|>Organization: Simon Fraser University, Burnaby, B.C., Canada
|>Date: Thu, 14 Oct 93 00:36:48 GMT+5:00
|>Lines: 50
|>Xref: jac.nuo.dec.com comp.lang.c:22504 comp.sys.next.bugs:896 comp.sys.dec:7062
|>
|>I was porting a program called SatTrack from Sun to neXT and VAX/VMS in
|>preparation for tracking the shuttle STS-58 due to launch on Thursday.
|>
|>The program was written by Manfred Bester, (DL5KR) is excellent, and works
|>well on the Sun platforms I have run it on.
|>
|>On the NeXT, I ran into som problems. The satellite orbital data is
|>read from ascii files which are parsed up calculated upon by SatTrack. One
|>function makes extensive use of atof(). Return values from that function
|>are wild -- beyond anything that could be called round-off error.
|>
|>I am not a great c programmer, so I wrote a little test program to validate my
|>understanding ot atof(). The outputs on various systems is below the source.
|>
|>--------------------
|>#include <math.h>
|>int main()
|>{
|> double f1;
|> char *s1 = "1234.567";
|>
|> f1 = atof(s1);
|> printf("%s, %f\n",s1, f1);
|>}
|>--------------------
|>
|>1) On SunOS 4.?
|> 1234.567, 1234.567000 [OK!]
|>
|>2) On NeXTOS 3.0
|> 1234.567, 1083394628.000000 [Not ok]
|>
|>3) Silicon Graphics IRIX 4.?
|> 1234.567, 1234.567000 [OK!]
|>
|>4) VAX/VMS
|> (D_FLOAT)
|> 1234.567, 1378108826.000000 [Not ok]
|>
|> (G_FLOAT)
|> 1234.567, 1245986995.000000 [Not ok]
|>
|>So, Sun and SGI seem to work while Next and VMS don't. Have I left something
|>out here? Compiler switches?
|>
|>Ideas appreciated.
|>--
|>Bill Baines, Operations and Tech. Support,
|>Simon Fraser University, Vancouver, British Columbia, Canada
|>bill@sfu.ca, (604) 291-3955, (fax 291-4242), VE7FML
|>
atof() is declared in stdlib.h, not math.h. Without a declaration
the routine is implicitly declared as returning an int. Just
change math.h to stdlib.h and it'll work on VAX. The ANSI C standard
requires the definition be in stdlib.h, so the change should still
work back on the SG and Sun machines.
--
Ken Cowan, ZK2-3/Q8 cowan@rtl.enet.dec.com
Digital Equipment Corporation decwrl!rtl!cowan
110 Spit Brook Rd,
Nashua, NH 03062
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: clib atof() question resolved... Thanks!!!
1993-10-14 4:36 clib atof() question Bill Baines
1993-10-14 13:06 ` Bob Doherty
1993-10-14 13:18 ` Ken Cowan
@ 1993-10-15 0:32 ` Bill Baines
2 siblings, 0 replies; 4+ messages in thread
From: Bill Baines @ 1993-10-15 0:32 UTC (permalink / raw)
In article <1993Oct14.043648.1611@sfu.ca> I posted the following code:
> --------------------
> #include <math.h>
> int main()
> {
> double f1;
> char *s1 = "1234.567";
>
> f1 = atof(s1);
> printf("%s, %f\n",s1, f1);
> }
> --------------------
Today I rec'd several replys -- most suggesting that I #include <stdlib.h>
which I did -- both in the above example, and in the original code I
am porting. PROBLEM SOLVED! Thanks again for your kind suggestions.
Several also mentioned that I should have checked the man page for atof()
which would have advised me that atof() was prototyped in stdlib.h.
Interesting, that NeXT 2.1, NeXT 3.0 and Sun 4.? don't mention stdlib.h
in their atof man page. Same goes for the NeXT Digital Librarian I have. (My
own system has been diddled up and down a few times, so I may not have the
latest man pages loaded -- perhaps I should reload the man pages from the
CD-Rom).
VAX/VMS help and SGI Irix do make mention of stdlib.h in their references to
atof().
Anyways, lesson learned... Thanks again for your kind responses...
--
Bill Baines, Operations and Tech. Support,
Simon Fraser University, Vancouver, British Columbia, Canada
bill@sfu.ca, (604) 291-3955, (fax 291-4242), VE7FML
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~1993-10-15 0:32 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1993-10-14 4:36 clib atof() question Bill Baines
1993-10-14 13:06 ` Bob Doherty
1993-10-14 13:18 ` Ken Cowan
1993-10-15 0:32 ` clib atof() question resolved... Thanks!!! Bill Baines
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox