From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fc89c,7e35f49d4d9340ab X-Google-Attributes: gidfc89c,public X-Google-Thread: 109fba,7e35f49d4d9340ab X-Google-Attributes: gid109fba,public X-Google-Thread: 1164f8,7e35f49d4d9340ab X-Google-Attributes: gid1164f8,public From: mathog@seqaxp.bio.caltech.edu Subject: Re: Division by zero crashes on DEC should be avoidable! Date: 1998/03/06 Message-ID: <6dpdce$jsg@gap.cco.caltech.edu>#1/1 X-Deja-AN: 331463416 References: <34FF7719.41C6@ned.dem.csiro.au> Organization: Biology Division, Caltech, Pasadena CA 91125 Reply-To: mathog@seqaxp.bio.caltech.edu Newsgroups: comp.sys.dec,comp.lang.c++,comp.unix.programmer In article <34FF7719.41C6@ned.dem.csiro.au>, Andrew Ellerton writes: >Dear All, > >This is possibly a simple question: > > On other UNIX platforms the application I have to port > to DEC works fine - including handling division by zero > with only a warning, presumably using not-a-number (NaN) > or INF symbols as the result. Sure, I know it should > never try to divide by zero, but it does. > > However, the C++ code will crash the entire application > on the DEC 4.0 version when it divides by zero. Is this > solvable by (for example) compiling with a certain switch? > For the OpenVMS version of DEC C++ there is a /IEEE_MODE, the HELP for it says: CXX /IEEE_MODE=option Selects the IEEE floating-point mode to be used if /FLOAT=IEEE_FLOAT is specified. You can select from the following options: FAST During program execution, only finite values (no infinities, NaNs, or denorms) are created. Exceptional conditions, such as floating-point overflow and divide-by-zero, are fatal. This is the default option. UNDERFLOW_TO_ZERO Generate infinities and NaNs. Flush denormalized results and underflow to zero without exceptions. DENORM_RESULTS Same as UNDERFLOW_TO_ZERO, except that denorms are generated. INEXACT Same as DENORM_RESULTS, except that inexact values are trapped. This is the slowest mode. The default is /IEEE_MODE=FAST. So, try something like -IEEE_MODE=UNDERFLOW_TO_ZERO (syntax is almost certainly different than that given here.) > Or is there any other way to stop it from crashing, or do > I have to resort to modifying the code? I consider think that it is a very bad idea to depend on your compiler having a mode which will enable it to ignore invalid operation results (divide by zero). (Except in languages with try/trap methods built into the standard.) Ok, so you find the right switch, and the program no longer crashes at this illegal operation, but what did it do with the resulting value? It runs to completion, but is the answer correct??? Regards, David Mathog mathog@seqaxp.bio.caltech.edu Manager, sequence analysis facility, biology division, Caltech ************************************************************************** * Affordable VMS? See: http://seqaxp.bio.caltech.edu/www/pcvms.html * **************************************************************************