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