TIP: Click on subject to list as thread! ANSI
echo: cis.os9.68000.osk
to: David A. Ferguson 73737,2471
from: David Breeding 72330,2051
date: 1995-08-18 00:55:07
subject: #21128-NeedHelpToTrapError107!?

#: 21140 S12/OS9/68000 (OSK)
    18-Aug-95  00:55:07
Sb: #21128-NeedHelpToTrapError107!?
Fm: David Breeding 72330,2051
To: David A. Ferguson 73737,2471

 > Help!,
 >
 > I need to know how to trap a floating point error.  Currently my program
 > is aborted when the result of a floating point operation 'under flows' to
 > zero.

 >
 > void main ()
 > {
 > float g;
 >
 > for (g = 1.0; ; g /= 3.1415)
 > printf("g=%g\n", g);
 > }
 >
 > Following are the last few lines that are printed before the program is
 > dumped.
 > g=1.62876e-37
 > g=5.18466e-38
 > g=1.65038e-38
 > Error #000:107
 > $

I tried the same thing (using MW cc 3.2), and got the same thing as you did.
However, changing the variable to a double eliminated that error, for some
reason.  Here's the output at the time it got so small it started to just print
zero's:

   g=1.84685e-307
   g=5.87888e-308
   g=1.87136e-308
   g=0
   g=0
   g=0 Error #000:003     <<< I hit CTRL-C

I let it run for some time, and it never did error.  Dunno if this will help or
not, but maybe..


                         -- David Breeding --
       CompuServe : 72330,2051             Delphi :  DBREEDING
    *** Composed with InfoXpress/OSK Vr. 1.02 & VED Vr. 2.4.0  ***

Press  !>

SOURCE: compuserve via textfiles.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.