Actual source code: ex3.c

petsc-3.13.6 2020-09-29
Report Typos and Errors

  2: static char help[] = "Tests catching of floating point exceptions.\n\n";

  4:  #include <petscsys.h>

  6: int CreateError(PetscReal x)
  7: {

 11:   x    = 1.0/x;
 12:   PetscPrintf(PETSC_COMM_SELF,"x = %g\n",(double)x);
 13:   return(0);
 14: }

 16: int main(int argc,char **argv)
 17: {
 19:   PetscInitialize(&argc,&argv,(char*)0,help);if (ierr) return ierr;
 20:   PetscPrintf(PETSC_COMM_SELF,"This is a contrived example to test floating pointing\n");
 21:   PetscPrintf(PETSC_COMM_SELF,"It is not a true error.\n");
 22:   PetscPrintf(PETSC_COMM_SELF,"Run with -fp_trap to catch the floating point error\n");
 23:   CreateError(0.0);
 24:   return 0;
 25: }


 28: /*

 30:     Because this example may produce different output on different machines we filter out everything.
 31:     This makes the test ineffective but currently we don't have a good way to know which machines should handle
 32:     the floating point exceptions properly.

 34: */
 35: /*TEST

 37:    test:
 38:       args: -fp_trap -error_output_stdout
 39:       filter: Error: true

 41: TEST*/