xref: /petsc/src/sys/tests/ex3.c (revision 327415f76d85372a4417cf1aaa14db707d4d6c04)
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;
109566063dSJacob 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*327415f7SBarry Smith   PetscFunctionBeginUser;
179566063dSJacob Faibussowitsch   PetscCall(PetscInitialize(&argc,&argv,(char*)0,help));
189566063dSJacob Faibussowitsch   PetscCall(PetscPrintf(PETSC_COMM_SELF,"This is a contrived example to test floating pointing\n"));
199566063dSJacob Faibussowitsch   PetscCall(PetscPrintf(PETSC_COMM_SELF,"It is not a true error.\n"));
209566063dSJacob Faibussowitsch   PetscCall(PetscPrintf(PETSC_COMM_SELF,"Run with -fp_trap to catch the floating point error\n"));
219566063dSJacob Faibussowitsch   PetscCall(CreateError(0.0));
22c4762a1bSJed Brown   return 0;
23c4762a1bSJed Brown }
24c4762a1bSJed Brown 
25c4762a1bSJed Brown /*
26c4762a1bSJed Brown 
27c4762a1bSJed Brown     Because this example may produce different output on different machines we filter out everything.
28c4762a1bSJed Brown     This makes the test ineffective but currently we don't have a good way to know which machines should handle
29c4762a1bSJed Brown     the floating point exceptions properly.
30c4762a1bSJed Brown 
31c4762a1bSJed Brown */
32c4762a1bSJed Brown /*TEST
33c4762a1bSJed Brown 
34c4762a1bSJed Brown    test:
35c4762a1bSJed Brown       args: -fp_trap -error_output_stdout
36c4762a1bSJed Brown       filter: Error: true
37c4762a1bSJed Brown 
38c4762a1bSJed Brown TEST*/
39