*BSD News Article 67312


Return to BSD News archive

Path: euryale.cc.adfa.oz.au!newshost.anu.edu.au!harbinger.cc.monash.edu.au!news.rmit.EDU.AU!news.unimelb.EDU.AU!munnari.OZ.AU!news.ecn.uoknor.edu!news.cis.okstate.edu!newsfeed.ksu.ksu.edu!news.physics.uiowa.edu!math.ohio-state.edu!howland.reston.ans.net!usc!news.cerf.net!nntp-server.caltech.edu!bombay.gps.caltech.edu!STAN
From: stan@bombay.gps.caltech.edu ("Stan")
Newsgroups: comp.unix.bsd.freebsd.misc
Subject: Weird arithmetic
Date: 28 Apr 1996 18:19:06 GMT
Organization: USGS
Lines: 50
Message-ID: <4m0cqq$bv0@gap.cco.caltech.edu>
Reply-To: stan@bombay.gps.caltech.edu
NNTP-Posting-Host: bombay.gps.caltech.edu

I downloaded a copy of a program called ephem to figure out astronomical 
stuff, and it's doing something that I really don't understand at all.

N.B. All variables in the routine in questions are declared double.

It's blowing up in the math library inside the sin function.  I compiled 
with gdb and found this:

There is a variable called ms:

(gdb) print ms
$2 = 1.4101357041089591

This looks reasonable.  Taking sin(ms) worked all right, but when we try 
to take sin(2*ms), all hell breaks loose.  I tried isolating the problem by 
adding a line:

x1 = 2*ms;

(gdb) print x1
$1 = -1.8800393335575473e+230

Note that I get an overflow.

Yet:

(gdb) print 2*ms
$3 = 2.8202714082179181

I can calculate 2*ms from gdb, yet it turns into overflow when the program 
does it.

I thought that the difference between 2*ms and 2.0*ms might be it, so I 
tried it:

x1 = 2.0 * ms;

(gdb) print x1
$1 = 8.275783586691418e-313

Now I get an underflow and the sin function still chokes.

I suspect that there is something very fundamental that I'm missing here.  
Anybody know what it is?

--
-------------------------------------------------------------------------------
Stan Schwarz                |     "I just want to live like Yogi Bear
stan@bombay.gps.caltech.edu |        He kicks ass on the average bear."
---------------------------------------------------- -Stukas Over Bedrock -----