home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.lang.fortran:4227 comp.lang.c:16089
- Path: sparky!uunet!destroyer!cs.ubc.ca!unixg.ubc.ca!sitka.triumf.ca!morgan
- From: morgan@sitka.triumf.ca (Morgan Burke)
- Newsgroups: comp.lang.fortran,comp.lang.c
- Subject: SGI floating point exceptions
- Date: 6 Nov 1992 18:40:06 GMT
- Organization: TRIUMF, Vancouver BC
- Lines: 78
- Distribution: world
- Message-ID: <1dee66INNe4a@iskut.ucs.ubc.ca>
- NNTP-Posting-Host: sitka.triumf.ca
-
- I'm having difficulty creating a floating point exception handler
- for an application running on SGI's Irix 4.0 (System V-based),
- with f77 3.4.
-
- According to the man pages, the routine "handle_sigfpes" is used
- to manage floating point exceptions (the normal signal processing
- facilities seem to have no effect). However, I get very strange
- results using this routine from both Fortran and C.
-
- First, the Fortran case:
-
- PROGRAM sig
- #include <fsigfpe.h>
- REAL*4 a/1.0/,b/0.0/
- CALL handle_sigfpes(FPE_ON,FPE_EN_DIVZERO,0,FPE_ABORT_ON_ERROR,0)
- WRITE(6,*) a/b
- WRITE(6,*) b**(-2)
- WRITE(6,*) LOG(b)
- END
-
- % f77 sig.f -lfpe
- % a.out
- 3.4028235E+38
- Infinity
- 3.4028235E+38
- Infinity
- 3.4028235E+38
- Infinity
- 3.4028235E+38
- ....and so on, in an infinite loop
-
- The normal output (ie. without the call to handle_sigfpes) is:
- Infinity
- Infinity
- Infinity
-
- Now, the C case:
-
- #include <sigfpe.h>
- #include <math.h>
- main()
- {
- float a=1.0,b=0.0;
- handle_sigfpes(_ON, _EN_DIVZERO, 0, _ABORT_ON_ERROR, 0 );
- printf("%e\n",a/b);
- printf("%e\n",pow(b,-2));
- printf("%e\n",log(b));
- }
-
- % cc sig.c -lfpe -lm
- % a.out
- 3.402823e+38
- 1.797693e+308
- sigfpe_catch: **ABORT(internal) - failure to analyze exception conditions.
- pc = 0x403a68, fcsr = 0x800420
- Floating exception (core dumped)
-
- Removing the call to handle_sigfpes, I get:
- Infinity
- Infinity
- -Infinity
-
- Questions:
- ==========
-
- 1. Why does the handler trap log(0) in C, but not an explicit
- divide-by-zero, when that is what I have asked for?
- 2. Why do results that are normally "Infinity" come back as legal
- floating point values (the maximal values, I assume) when the
- handler is used?
- 3. Any idea why the Fortran routine goes berserk?
- 4. Why does LOG(0) return +Infinity in f77?
- 5. I want the application to core dump (like it did for log(0) in C)
- for all of these examples. Anybody know a better way to do this?
- 6. Who do I hunt down and kill for stupidities (IMHO) like "NaN" and
- "Infinity" in the IEEE floating point standard?
-
- -- Morgan Burke (morgan@reg.triumf.ca)
-