1c4762a1bSJed Brown 2c4762a1bSJed Brown static char help[] = "Tests catching of floating point exceptions.\n\n"; 3c4762a1bSJed Brown 4c4762a1bSJed Brown #include <petscsys.h> 5c4762a1bSJed Brown 6c4762a1bSJed Brown int CreateError(PetscReal x) 7c4762a1bSJed Brown { 8c4762a1bSJed Brown PetscFunctionBegin; 9c4762a1bSJed Brown x = 1.0/x; 10*9566063dSJacob Faibussowitsch PetscCall(PetscPrintf(PETSC_COMM_SELF,"x = %g\n",(double)x)); 11c4762a1bSJed Brown PetscFunctionReturn(0); 12c4762a1bSJed Brown } 13c4762a1bSJed Brown 14c4762a1bSJed Brown int main(int argc,char **argv) 15c4762a1bSJed Brown { 16*9566063dSJacob Faibussowitsch PetscCall(PetscInitialize(&argc,&argv,(char*)0,help)); 17*9566063dSJacob Faibussowitsch PetscCall(PetscPrintf(PETSC_COMM_SELF,"This is a contrived example to test floating pointing\n")); 18*9566063dSJacob Faibussowitsch PetscCall(PetscPrintf(PETSC_COMM_SELF,"It is not a true error.\n")); 19*9566063dSJacob Faibussowitsch PetscCall(PetscPrintf(PETSC_COMM_SELF,"Run with -fp_trap to catch the floating point error\n")); 20*9566063dSJacob Faibussowitsch PetscCall(CreateError(0.0)); 21c4762a1bSJed Brown return 0; 22c4762a1bSJed Brown } 23c4762a1bSJed Brown 24c4762a1bSJed Brown /* 25c4762a1bSJed Brown 26c4762a1bSJed Brown Because this example may produce different output on different machines we filter out everything. 27c4762a1bSJed Brown This makes the test ineffective but currently we don't have a good way to know which machines should handle 28c4762a1bSJed Brown the floating point exceptions properly. 29c4762a1bSJed Brown 30c4762a1bSJed Brown */ 31c4762a1bSJed Brown /*TEST 32c4762a1bSJed Brown 33c4762a1bSJed Brown test: 34c4762a1bSJed Brown args: -fp_trap -error_output_stdout 35c4762a1bSJed Brown filter: Error: true 36c4762a1bSJed Brown 37c4762a1bSJed Brown TEST*/ 38