View Issue Details Jump to Notes ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0010912ITKpublic2010-06-29 20:392010-10-29 11:56
ReporterHans Johnson 
Assigned Tokentwilliams 
PrioritynormalSeverityminorReproducibilityhave not tried
StatusclosedResolutionfixed 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version 
Summary0010912: Add support for identifying floating point exceptions
DescriptionThe 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.

=====================
TagsNo tags attached.
Resolution Date
Sprint
Sprint Statusbacklog
Attached Filesc file icon fe-handling-example.c [^] (12,031 bytes) 2010-06-29 20:43
gz file icon floatingPointUpdateFiles.tar.gz [^] (14,550 bytes) 2010-07-12 14:35
gz file icon ITK-FPEFixes.tar.gz [^] (6,253 bytes) 2010-07-15 14:33
patch file icon 0001-Add-missing-cstring-include.patch [^] (795 bytes) 2010-07-16 11:08 [Show Content]

 Relationships

  Notes
(0021192)
Hans Johnson (developer)
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 (developer)
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 (developer)
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 (developer)
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 (developer)
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 (developer)
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 (developer)
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.

 Issue History
Date Modified Username Field Change
2010-06-29 20:39 Hans Johnson New Issue
2010-06-29 20:39 Hans Johnson Status new => assigned
2010-06-29 20:39 Hans Johnson Assigned To => Hans Johnson
2010-06-29 20:43 Hans Johnson File Added: fe-handling-example.c
2010-06-29 21:25 Hans Johnson File Added: ITK_FPE.tar.gz
2010-06-29 21:27 Hans Johnson Note Added: 0021192
2010-07-01 15:11 Matthew McCormick Note Added: 0021209
2010-07-12 14:35 Hans Johnson File Added: floatingPointUpdateFiles.tar.gz
2010-07-12 14:35 Hans Johnson File Deleted: ITK_FPE.tar.gz
2010-07-12 14:39 Hans Johnson Note Added: 0021363
2010-07-12 14:39 Hans Johnson Assigned To Hans Johnson => kentwilliams
2010-07-15 14:33 kentwilliams File Added: ITK-FPEFixes.tar.gz
2010-07-15 14:35 kentwilliams Note Added: 0021400
2010-07-15 23:32 Matthew McCormick Note Added: 0021405
2010-07-16 10:33 kentwilliams Note Added: 0021408
2010-07-16 11:08 Matthew McCormick File Added: 0001-Add-missing-cstring-include.patch
2010-07-16 11:09 Matthew McCormick Note Added: 0021409
2010-10-29 11:56 kentwilliams Sprint Status => backlog
2010-10-29 11:56 kentwilliams Status assigned => closed
2010-10-29 11:56 kentwilliams Resolution open => fixed


Copyright © 2000 - 2018 MantisBT Team