MantisBT - ITK
View Issue Details
0010912ITKpublic2010-06-29 20:392010-10-29 11:56
Hans Johnson 
kentwilliams 
normalminorhave not tried
closedfixed 
 
 
backlog
0010912: Add support for identifying floating point exceptions
The BORLAND compiler has one redeeming quality in that it can catch divide-by-zero floating point exceptions.

I believe that any GCC compiler should also be able to catch Divide-By-Zero exceptions.

A new FPE set of tests should be created in the ITK test suite that tests weather FPE are being caught. They should not raise exceptions with the current settings, and they should raise exceptions once instrumented with the new signalling.

=====================
No tags attached.
c fe-handling-example.c (12,031) 2010-06-29 20:43
https://public.kitware.com/Bug/file/3215/fe-handling-example.c
gz floatingPointUpdateFiles.tar.gz (14,550) 2010-07-12 14:35
https://public.kitware.com/Bug/file/3239/floatingPointUpdateFiles.tar.gz
gz ITK-FPEFixes.tar.gz (6,253) 2010-07-15 14:33
https://public.kitware.com/Bug/file/3248/ITK-FPEFixes.tar.gz
patch 0001-Add-missing-cstring-include.patch (795) 2010-07-16 11:08
https://public.kitware.com/Bug/file/3251/0001-Add-missing-cstring-include.patch
Issue History
2010-06-29 20:39Hans JohnsonNew Issue
2010-06-29 20:39Hans JohnsonStatusnew => assigned
2010-06-29 20:39Hans JohnsonAssigned To => Hans Johnson
2010-06-29 20:43Hans JohnsonFile Added: fe-handling-example.c
2010-06-29 21:25Hans JohnsonFile Added: ITK_FPE.tar.gz
2010-06-29 21:27Hans JohnsonNote Added: 0021192
2010-07-01 15:11Matthew McCormickNote Added: 0021209
2010-07-12 14:35Hans JohnsonFile Added: floatingPointUpdateFiles.tar.gz
2010-07-12 14:35Hans JohnsonFile Deleted: ITK_FPE.tar.gz
2010-07-12 14:39Hans JohnsonNote Added: 0021363
2010-07-12 14:39Hans JohnsonAssigned ToHans Johnson => kentwilliams
2010-07-15 14:33kentwilliamsFile Added: ITK-FPEFixes.tar.gz
2010-07-15 14:35kentwilliamsNote Added: 0021400
2010-07-15 23:32Matthew McCormickNote Added: 0021405
2010-07-16 10:33kentwilliamsNote Added: 0021408
2010-07-16 11:08Matthew McCormickFile Added: 0001-Add-missing-cstring-include.patch
2010-07-16 11:09Matthew McCormickNote Added: 0021409
2010-10-29 11:56kentwilliamsSprint Status => backlog
2010-10-29 11:56kentwilliamsStatusassigned => closed
2010-10-29 11:56kentwilliamsResolutionopen => fixed

Notes
(0021192)
Hans Johnson   
2010-06-29 21:27   
Alternate c++ methods:

? Testing/Code/Review/.itkBinaryContourImageFilterTest.cxx.swp
Index: Code/Common/itkTestMain.h
===================================================================
RCS file: /cvsroot/Insight/Insight/Code/Common/itkTestMain.h,v
retrieving revision 1.33
diff -r1.33 itkTestMain.h
44a45
> #include <csignal>
77a79,92
>
> static void sigfpe_handl(int sig)
> {
> printf("Argggh..Division by zero ! (or other fpe): SIGNAL=%d\n",sig);
> //..some more
> exit(-1);
> }
> //void sigint_handl(int sig)
> //{
> // printf("Program is exiting..: SIGNAL=%d\n",sig);
> // exit(0);
> //}
>
>
79a95,96
> //std::signal(SIGFPE,sigfpe_handl);
> //
Index: Testing/Code/Review/itkBinaryContourImageFilterTest.cxx
===================================================================
RCS file: /cvsroot/Insight/Insight/Testing/Code/Review/itkBinaryContourImageFilterTest.cxx,v
retrieving revision 1.4
diff -r1.4 itkBinaryContourImageFilterTest.cxx
39a40,54
> //Try to force a failure due to floating point exception.
> //
> double failure=100;
> double reallybig=1E200L;
> int myint=1000;
> for(int i=10; i >=0 ; i--)
> {
> failure+=failure/static_cast<double>(i);
> //NOTE: the last iteration in this loop i=0.0, and then it should throw a floating point exception.
> //std::cout << "WARNING: failure should thow FPE: " << failure << std::endl;
> myint=myint/i;
> std::cout << "WARNING: failure should thow FPE: " << myint << std::endl;
> //std::cout << reallybig*reallybig*static_cast<double>(i) << std::endl;
> }
>
(0021209)
Matthew McCormick   
2010-07-01 15:11   
Cool. Looks like a nice convenient class. Maybe a way to configure which exceptions are enabled in the class would be nice. Also, my preference is to have an exception thrown rather than call abort(). That way I can catch it and ignore it or handle it if needed. You can always get a stack trace if you run 'catch throw' in gdb.
(0021363)
Hans Johnson   
2010-07-12 14:39   
The file fe-handling-example.c is a standalone program that seems to display the desired behavior.

The file floatingPointUpdateFiles.tar.gz should be extracted in the Insight code directory, and contains the start of the code necessary to implement this across all tests in ITK. This is a copy of some of the framework from VTK, but does not use the same mechanisms as fe-handling-example.c, and does not catch the same floating point exceptions.

TODO: Merge these two exception handling routinges, and make work on at least one platform type (i.e. it does not need to work under any compiler except the gcc compiler)

TODO: Make a set of tests to ensure that exceptions are actually caught.
(0021400)
kentwilliams   
2010-07-15 14:35   
I added a new file ITKFPE-fixes.tar.gz that is a tested fix. It comprises a patchfile to existing files, plus the new files needed.
(0021405)
Matthew McCormick   
2010-07-15 23:32   
I needed to
#include <cstring>

for the code to compile.

I some ITK code that I use which throws C++ exceptions in a floating point signal handler. Apparently, further reading indicates that is bad practice because it is not guaranteed to work. Commenting in your exception code the underflow test would fail for whatever reason, though the other tests would pass. Live and learn.
(0021408)
kentwilliams   
2010-07-16 10:33   
Matthew -- to what file did you need to add #include <cstring>? What platform were you compiling on?
(0021409)
Matthew McCormick   
2010-07-16 11:09   
Sorry for the lack of detail -- a patch is attached. cstring is needed for memset(). This is Linux/gcc-4.4.3. Newer gcc's tend to catch more errors.