/[ascend]/trunk/base/generic/compiler/safe.c
ViewVC logotype

Diff of /trunk/base/generic/compiler/safe.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 90 by johnpye, Wed Dec 7 15:44:43 2005 UTC revision 91 by johnpye, Wed Dec 7 16:17:03 2005 UTC
# Line 59  void safe_error_to_stderr(enum safe_err Line 59  void safe_error_to_stderr(enum safe_err
59      case safe_ok:      case safe_ok:
60        return;        return;
61      case safe_div_by_zero:      case safe_div_by_zero:
62        FPRINTF(stderr,"WARNING: Division by Zero\n");        error_reporter(ASC_PROG_WARNING,NULL,0,"Division by zero");
63      case safe_complex_result:      case safe_complex_result:
64        FPRINTF(stderr,"WARNING: Complex Result\n");        error_reporter(ASC_PROG_WARNING,NULL,0,"Complex result");
65        break;        break;
66      case safe_overflow:      case safe_overflow:
67        FPRINTF(stderr,"WARNING: Overflow\n");        error_reporter(ASC_PROG_WARNING,NULL,0,"Overflow");
68        break;        break;
69      case safe_underflow:      case safe_underflow:
70        FPRINTF(stderr,"WARNING: Underflow\n");        error_reporter(ASC_PROG_WARNING,NULL,0,"Underflow");
71        break;        break;
72      case safe_range_error:      case safe_range_error:
73        FPRINTF(stderr,"WARNING: Function Range Error\n");        error_reporter(ASC_PROG_WARNING,NULL,0,"Function range error");
74        break;        break;
75      }      }
76  }  }
# Line 222  double safe_rec(double x,enum safe_err * Line 222  double safe_rec(double x,enum safe_err *
222     if( x == 0.0 ) {     if( x == 0.0 ) {
223        double bogus = BIGNUM;        double bogus = BIGNUM;
224        if( safe_print_errors ) {        if( safe_print_errors ) {
225       error_reporter(ASC_USER_ERROR,NULL,0,"safe_rec: divide by zero undefined, returning %g",bogus);       error_reporter(ASC_USER_ERROR,NULL,0,"Divide by zero in 1/x expr: returning %g",bogus);
226        }        }
227        *safe = safe_div_by_zero;        *safe = safe_div_by_zero;
228        return( bogus );        return( bogus );
# Line 245  double safe_cube(register double x,enum Line 245  double safe_cube(register double x,enum
245        if ( fabs(x) > CUBRTHUGE) {        if ( fabs(x) > CUBRTHUGE) {
246          bogus=BIGNUM;          bogus=BIGNUM;
247          if( safe_print_errors ) {          if( safe_print_errors ) {
248             error_reporter(ASC_USER_ERROR,NULL,0,"safe_cube: Overflow calculation requested, returning %g.",bogus);             error_reporter(ASC_USER_ERROR,NULL,0,"Overflow in x^3 expr: returning %g.",bogus);
249          }          }
250        } else {        } else {
251          bogus=0.0;          bogus=0.0;
252          if( safe_print_errors ) {          if( safe_print_errors ) {
253               error_reporter(ASC_USER_ERROR,NULL,0,"safe_cube: Underflow calculation requested, returning %g.",bogus);               error_reporter(ASC_USER_ERROR,NULL,0,"Underflow in x^3 expr: returning %g.",bogus);
254          }          }
255        }        }
256        *safe = safe_underflow;        *safe = safe_underflow;
# Line 275  double safe_erf_inv(double x,enum safe_e Line 275  double safe_erf_inv(double x,enum safe_e
275     if( x >= 1.0 ) {     if( x >= 1.0 ) {
276        double bogus = sign*BIGNUM;        double bogus = sign*BIGNUM;
277        if( safe_print_errors ) {        if( safe_print_errors ) {
278       error_reporter(ASC_USER_ERROR,NULL,0,"safe_erf_inv: Inverse erf is undefined at %g, returning %g",x,bogus);          error_reporter(ASC_USER_ERROR,NULL,0,"inv_erf undefined at %g: returning %g",x,bogus);
279        }        }
280        *safe = safe_range_error;        *safe = safe_range_error;
281        return(bogus);        return(bogus);
# Line 291  double safe_erf_inv(double x,enum safe_e Line 291  double safe_erf_inv(double x,enum safe_e
291         ***  always be positive (?).         ***  always be positive (?).
292         **/         **/
293        if( dy < 0.0 && safe_print_errors ) {        if( dy < 0.0 && safe_print_errors ) {
294       error_reporter(ASC_USER_ERROR,NULL,0,"safe_erf_inv: Found negative slope of %g on erf.",dy);          error_reporter(ASC_USER_ERROR,NULL,0,"Found negative slope of %g on erf_inv.",dy);
295        }        }
296     } while( safe_ok && dy > CONV );     } while( safe_ok && dy > CONV );
297     return( y * sign );     return( y * sign );
# Line 306  double safe_lnm_inv(double x,enum safe_e Line 306  double safe_lnm_inv(double x,enum safe_e
306     if( x > (DBL_MAX > 1.0e308 ? 709.196209 : log(DBL_MAX)) ) {     if( x > (DBL_MAX > 1.0e308 ? 709.196209 : log(DBL_MAX)) ) {
307        double bogus = BIGNUM;        double bogus = BIGNUM;
308        if( safe_print_errors ) {        if( safe_print_errors ) {
309           error_reporter(ASC_USER_ERROR,NULL,0,"safe_lnm_inv: Argument %g too large, returning %g.",x,bogus);           error_reporter(ASC_USER_ERROR,NULL,0,"Argument %g too large in lnm_inv: returning %g.",x,bogus);
310        }        }
311        *safe = safe_range_error;        *safe = safe_range_error;
312        return(bogus);        return(bogus);
# Line 385  double safe_arcsin_D0(double x,enum safe Line 385  double safe_arcsin_D0(double x,enum safe
385     if( x < -1.0 || 1.0 < x ) {     if( x < -1.0 || 1.0 < x ) {
386        double bogus = 0.0;        double bogus = 0.0;
387        if( safe_print_errors ) {        if( safe_print_errors ) {
388       error_reporter(ASC_USER_ERROR,NULL,0,"safe_arcsin_D0: Function arcsin is undefined at %g, Returning %g.",x,bogus);       error_reporter(ASC_USER_ERROR,NULL,0,"arcsin_D0: arcsin undefined at %g: Returning %g.",x,bogus);
389        }        }
390        *safe = safe_range_error;        *safe = safe_range_error;
391        return(bogus);        return(bogus);
# Line 404  double safe_arccos_D0(double x,enum safe Line 404  double safe_arccos_D0(double x,enum safe
404     if( x < -1.0 || 1.0 < x ) {     if( x < -1.0 || 1.0 < x ) {
405        double bogus = 0.0;        double bogus = 0.0;
406        if( safe_print_errors ) {        if( safe_print_errors ) {
407       error_reporter(ASC_USER_ERROR,NULL,0,"safe_arccos_D0: Function arccos is undefined at %g, returning %g.",x,bogus);       error_reporter(ASC_USER_ERROR,NULL,0,"arccos_D0: arccos undefined at %g: returning %g.",x,bogus);
408        }        }
409        *safe = safe_range_error;        *safe = safe_range_error;
410        return(bogus);        return(bogus);
# Line 417  double safe_arccosh_D0(double x,enum saf Line 417  double safe_arccosh_D0(double x,enum saf
417     if( x < 1.0 ) {     if( x < 1.0 ) {
418        double bogus = 0.0;        double bogus = 0.0;
419        if( safe_print_errors ) {        if( safe_print_errors ) {
420       error_reporter(ASC_USER_ERROR,NULL,0,"safe_arccosh_D0: Function arccosh is undefined at %g, returning %g.",x,bogus);       error_reporter(ASC_USER_ERROR,NULL,0,"arccosh_D0: undefined at %g: returning %g.",x,bogus);
421        }        }
422        *safe = safe_range_error;        *safe = safe_range_error;
423        return(bogus);        return(bogus);
# Line 437  double safe_arctanh_D0(double x,enum saf Line 437  double safe_arctanh_D0(double x,enum saf
437     if( x < -1.0 || 1.0 < x ) {     if( x < -1.0 || 1.0 < x ) {
438        double bogus = 0.0;        double bogus = 0.0;
439        if( safe_print_errors ) {        if( safe_print_errors ) {
440       error_reporter(ASC_USER_ERROR,NULL,0,"safe_arctanh_D0: Function arctanh is undefined at %g, returning %g.",x,bogus);       error_reporter(ASC_USER_ERROR,NULL,0,"arctanh_D0: undefined at %g: returning %g.",x,bogus);
441        }        }
442        *safe = safe_range_error;        *safe = safe_range_error;
443        return(bogus);        return(bogus);
# Line 458  double safe_exp_D0(double x,enum safe_er Line 458  double safe_exp_D0(double x,enum safe_er
458     if( x > (DBL_MAX > 1.0e308 ? 709.196209 : log(DBL_MAX)) ) {     if( x > (DBL_MAX > 1.0e308 ? 709.196209 : log(DBL_MAX)) ) {
459        double bogus = BIGNUM;        double bogus = BIGNUM;
460        if( safe_print_errors ) {        if( safe_print_errors ) {
461       error_reporter(ASC_USER_ERROR,NULL,0,"safe_exp_D0: Argument %g too large, returning %g.",x,bogus);          error_reporter(ASC_USER_ERROR,NULL,0,"exp_D0: Argument %g too large: returning %g.",x,bogus);
462        }        }
463        *safe = safe_range_error;        *safe = safe_range_error;
464        return(bogus);        return(bogus);
# Line 471  double safe_ln_D0(double x,enum safe_err Line 471  double safe_ln_D0(double x,enum safe_err
471     if( x <= 0.0 ) {     if( x <= 0.0 ) {
472        double bogus = -BIGNUM;        double bogus = -BIGNUM;
473        if( safe_print_errors ) {        if( safe_print_errors ) {
474       error_reporter(ASC_USER_ERROR,NULL,0,"safe_ln_D0: Natural log undefined at %g. Returning %g.",x,bogus);       error_reporter(ASC_USER_ERROR,NULL,0,"ln_D0: undefined at %g: Returning %g.",x,bogus);
475        }        }
476        *safe = safe_range_error;        *safe = safe_range_error;
477        return(bogus);        return(bogus);
# Line 502  double safe_sqrt_D0(double x,enum safe_e Line 502  double safe_sqrt_D0(double x,enum safe_e
502        double bogus;        double bogus;
503        bogus = -sqrt(-x);        bogus = -sqrt(-x);
504        if( safe_print_errors ) {        if( safe_print_errors ) {
505       error_reporter(ASC_USER_ERROR,NULL,0,"safe_sqrt_D0: Square root undefined at %g, returning %g.",x,bogus);       error_reporter(ASC_USER_ERROR,NULL,0,"sqrt_D0: undefined at %g: returning %g.",x,bogus);
506        }        }
507        *safe = safe_complex_result;        *safe = safe_complex_result;
508        return(bogus);        return(bogus);
# Line 698  double safe_tan_D2(double x,enum safe_er Line 698  double safe_tan_D2(double x,enum safe_er
698     if( fabs(cos(x)) == 0.0 ) {     if( fabs(cos(x)) == 0.0 ) {
699        double bogus = BIGNUM;        double bogus = BIGNUM;
700        if( safe_print_errors ) {        if( safe_print_errors ) {
701           error_reporter(ASC_USER_ERROR,NULL,0,"safe_tan_D2: Tan derivative infinite at %g, returning %g.",x,bogus);           error_reporter(ASC_USER_ERROR,NULL,0,"tan_D2: Infinite at %g: returning %g.",x,bogus);
702        }        }
703        *safe = safe_range_error;        *safe = safe_range_error;
704        return(bogus);        return(bogus);
# Line 735  double safe_arccosh_D2(double x,enum saf Line 735  double safe_arccosh_D2(double x,enum saf
735     if( fabs(x) <= 1.0 ) {     if( fabs(x) <= 1.0 ) {
736        double bogus = -BIGNUM;        double bogus = -BIGNUM;
737        if( safe_print_errors ) {        if( safe_print_errors ) {
738       error_reporter(ASC_USER_ERROR,NULL,0,"safe_arccosh_D2: Arccosh undefined at %g, returning %g",x,bogus);       error_reporter(ASC_USER_ERROR,NULL,0,"arccosh_D2: Undefined at %g: returning %g",x,bogus);
739        }        }
740        *safe = safe_range_error;        *safe = safe_range_error;
741        return(bogus);        return(bogus);
# Line 754  double safe_arctanh_D2(double x,enum saf Line 754  double safe_arctanh_D2(double x,enum saf
754     if( fabs(x) == 1.0 ) {     if( fabs(x) == 1.0 ) {
755        double bogus = BIGNUM;        double bogus = BIGNUM;
756        if( safe_print_errors ) {        if( safe_print_errors ) {
757       error_reporter(ASC_USER_ERROR,NULL,0,"safe_arctanh_D2: Arctanh undefined at %g, returning %g.",x,bogus);       error_reporter(ASC_USER_ERROR,NULL,0,"arctanh_D2: undefined at %g: returning %g.",x,bogus);
758        }        }
759        *safe = safe_range_error;        *safe = safe_range_error;
760        return(bogus);        return(bogus);
# Line 813  double safe_cbrt_D2(double x,enum safe_e Line 813  double safe_cbrt_D2(double x,enum safe_e
813     if( fabs(x) == 0.0 ) {     if( fabs(x) == 0.0 ) {
814        double bogus = BIGNUM;        double bogus = BIGNUM;
815        if( safe_print_errors ) {        if( safe_print_errors ) {
816       error_reporter(ASC_USER_ERROR,NULL,0,"safe_cbrt_D2: Cbrt undefined at %g, returning %g.",x,bogus);       error_reporter(ASC_USER_ERROR,NULL,0,"cbrt_D2: undefined at %g: returning %g.",x,bogus);
817        }        }
818        *safe = safe_range_error;        *safe = safe_range_error;
819        return(bogus);        return(bogus);
# Line 856  double safe_cos_Dn(double x,int n,enum s Line 856  double safe_cos_Dn(double x,int n,enum s
856           return( sin(x) );           return( sin(x) );
857     }     }
858     if( safe_print_errors ) {     if( safe_print_errors ) {
859        error_reporter(ASC_USER_ERROR,NULL,0,"safe_cos_D: Unreachable point reached.");        error_reporter(ASC_USER_ERROR,NULL,0,"cos_D: Unreachable point reached?!?");
860     }     }
861     *safe = safe_range_error;     *safe = safe_range_error;
862     return 0.0;     return 0.0;
# Line 952  double safe_pow_D0(double x,double y,enu Line 952  double safe_pow_D0(double x,double y,enu
952       double bogus;       double bogus;
953       bogus = y < 0.0 ? BIGNUM : 0.0;       bogus = y < 0.0 ? BIGNUM : 0.0;
954       if( safe_print_errors ) {       if( safe_print_errors ) {
955          error_reporter(ASC_USER_ERROR,NULL,0,"safe_pow_D0: %g raised to %g power undefined, returning %g",x,y,bogus);          error_reporter(ASC_USER_ERROR,NULL,0,"pow_D0: %g raised to power %g undefined: returning %g",x,y,bogus);
956       }       }
957       *safe = safe_range_error;       *safe = safe_range_error;
958       return(bogus);       return(bogus);
# Line 969  double safe_pow_D0(double x,double y,enu Line 969  double safe_pow_D0(double x,double y,enu
969        default: {        default: {
970       double bogus = cheap_pow(-x,y,safe);       double bogus = cheap_pow(-x,y,safe);
971       if( safe_print_errors ) {       if( safe_print_errors ) {
972          error_reporter(ASC_USER_ERROR,NULL,0,"safe_pow_D0: %g raised to %g power undefined, returning %g",x,y,bogus);          error_reporter(ASC_USER_ERROR,NULL,0,"pow_D0: %g raised to power %g undefined: returning %g",x,y,bogus);
973    
974       }       }
975       *safe = safe_range_error;       *safe = safe_range_error;

Legend:
Removed from v.90  
changed lines
  Added in v.91

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22