FLOATING POINT EXCEPTIONS ( 6/7/2000) - (14/7/2000)
--------------------------------------------------



A problem with g77 is that there is  no general control over
whether or not floating-point exceptions are trapped or ignored.
The default procedure is to produce a NaN or infinity and
continue the calculation.
(see http://krispc6.physik.uni-karlsruhe.de/usr/share/doc/glibc-doc/html/libc_19.html.)


Information to handle this problem exists at 

 http://linux.open.ac.uk/issue40/trap.txt  and
 http://www.suburbia.net/~billm/floating-point/index.html


Making use of these references, a set of fortran-callable c-routines
has been written to enable/disable, clear and test for divide-by-zero,
overflow and invalid. Inexact  is not checked since it is not an error.

The c-routines are

 fpenab  - enable exceptions
 fpdisab - disable exceptions
 fptest  - test exceptions
 fpclear - clear exceptions

 fptest2(nn) - test exceptions: to facilitate debugging, fptest2  returns nn .ne. zero if an exception occurs.  


 and

 hanfpe  - is a fortran routine that prints a message and stops the program when called via
           external hanfpe
           call signal(8,hanfpe)
           It appears that, in contrast to signal 2, it is not possible to continue execution of the program.




To make use of these routines compile and link using

f77 -fno-automatic -Wuninitialized  -g   -o     $2   $1.f `/cern/pro/bin/cernlib genlib pdflib mathlib graflib/X11 `\
  -L/area18/data/skilli/linuxs/fpe/wmexcp-0.4.2/fexcp  -lfpuexc\
  -L/area18/data/skilli/linuxs/fpe/wmexcp-0.4.2/fenv  -lfenv\

and see /area18/data/skilli/linuxs/testerr3.f  for a fortran program that tests
for exceptions and illustrates the use of the above routines.

Notice that if exceptions have been enabled ( to check a particular region of code),
it is not sufficient to simply disable exceptions subsequently ( to run without code checking),
but it is necessary to clear the exceptions also; if this is not done the system traps
on the next floating point operation even if it is a valid operation.
This can be checked by running testerr3 with  gdb  using  0 0 0 0 1 as input;  
it will be found that an exception occurs at a=a+1 (line 86).
A further point is that fptest indicates exceptions even if exceptions have not been enabled.