🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.msdos.programmer
Article #6532

Floating point error:Stack Overflow - Huh?

#6532
From: Michael Alan Corn
Date: Fri, 18 Dec 1992 04:34
38 lines
2449 bytes
Hello,
        I was hoping that someone could provide a good explanation of an
        error that BC3.1++ was reporting. After calling a certain function
        around 12 or so times, the program terminates with
        "Floating point error: Stack fault".  This is on a 386 with no co
        -processor installed, I rely upon the emulation code of the compiler.
        The function in question computes a number of parameters related to the
        moon (position, distance, etc..), It is VERY math intensive, requiring
        around 160 lines of code consisting of almost all trig functions.
        On top of that I declare all the variables to be long doubles, to
        maximize accuracy.  Thr routine worked fine until I added the following
        code that computes the illuminated fraction of the moons disk, its
        distance in earth radii and kilometers, and its geocentric diameter.
        The added code is below. The function returns (as I have left it below)
        a reference to a structure.  The values computed are dead nuts, so I'm
        baffled what is going wrong.  The manual says "This error does not
        normally occur ...." but really provides no good explanation or method
        to fix this.  Any help would be greatly appreciated, and indebt me
        and any future generations for eternity. Mike
macg9505@uxa.cso.uiuc.edu
:

NB: the rad variable converts degrees to radians and vice-versa

long double d = acosl(cosl(moon.gamma*rad - sunlong*rad)*cosl(moon.beta*rad));
long double i = (180 - (d/rad) - (0.1468 * ((1-0.0549*sinl(Mprime))/(1- 0.0167*sinl(M))) * sinl(d)));

               	moon.illum_frac = (1 + cosl(i*rad))/2;
               	moon.dist_e_radii = 1/sinl(moon.TT*rad);
               	moon.dist_klm = 6378.14/sinl(moon.TT*rad);
               	moon.geocen_diam = 0.272476 * moon.TT*3600;//convert to seconds of arc
   Moonptr ip;
   Moonref ir;
   ip = &moon;
   ir = &ip;
		return ir;
}
Technical Details
Message-ID: <BzFu1z.MvJ@news.cso.uiuc.edu>
Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!sdd.hp.com!ux1.cso.uiuc.edu!news.cso.uiuc.edu!uxa.cso.uiuc.edu!macg9505

Show Full Headers
Complete Article Headers
Newsgroups: comp.os.msdos.programmer
Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!sdd.hp.com!ux1.cso.uiuc.edu!news.cso.uiuc.edu!uxa.cso.uiuc.edu!macg9505
From: macg9505@uxa.cso.uiuc.edu (Michael Alan Corn)
Subject: Floating point error:Stack Overflow - Huh?
Message-ID: <BzFu1z.MvJ@news.cso.uiuc.edu>
Sender: usenet@news.cso.uiuc.edu (Net Noise owner)
Organization: University of Illinois at Urbana
Date: Fri, 18 Dec 1992 04:34:46 GMT
Lines: 38