VTK/Examples/Cxx/SimpleOperations/FloatingPointExceptions
From KitwarePublic
This example makes the illegal division by zero produce an error:
Error: Floating point exception detected. Signal 8
rather than simply store "inf" in y.
FloatingPointExceptions.cxx
#include <vtkFloatingPointExceptions.h> int main(int, char *[]) { // Disabled by default with gcc or visual studio. // Enabled by default by Borland CC. vtkFloatingPointExceptions::Enable(); double x = 0.0; double y = 1.0/x; // floating-point exception std::cout << "x: " << x << " y: " << y << std::endl; return EXIT_SUCCESS; }
CMakeLists.txt
cmake_minimum_required(VERSION 2.8) PROJECT(WidthHeight) find_package(VTK REQUIRED) include(${VTK_USE_FILE}) if (APPLE) add_executable(WidthHeight MACOSX_BUNDLE WidthHeight.cxx) else() add_executable(WidthHeight WidthHeight.cxx) endif() if(VTK_LIBRARIES) target_link_libraries(WidthHeight ${VTK_LIBRARIES}) else() target_link_libraries(WidthHeight vtkHybrid vtkCommon) endif()