double MyParser::EvalRemoveSingularity(double *xvar) { try { double result = Eval(); if ( gsl_isinf(result) || gsl_isnan(result) ) throw Singularity(); return result; } catch (Singularity) { try { if (isinf(Eval())) throw Pole(); int n; frexp (*xvar, &n); double xp = *xvar + ldexp(DBL_EPSILON,n); double xm = *xvar - ldexp(DBL_EPSILON,n); *xvar = xp; double yp = Eval(); if (gsl_isinf(yp) || gsl_isnan(yp)) throw Pole(); *xvar = xm; double ym = Eval(); if (gsl_isinf(ym) || gsl_isnan(ym)) throw Pole(); return (yp + ym)/2; } catch (Pole) { SingularityErrorMessage(*xvar); return GSL_ESING; } } }
globle double CscFunction( void *theEnv) { double num, tv; if (SingleNumberCheck(theEnv,"csc",&num) == FALSE) return(0.0); tv = sin(num); if ((tv < SMALLEST_ALLOWED_NUMBER) && (tv > -SMALLEST_ALLOWED_NUMBER)) { SingularityErrorMessage(theEnv,"csc"); return(0.0); } return(1.0 / tv); }
globle double CothFunction( void *theEnv) { double num; if (SingleNumberCheck(theEnv,"coth",&num) == FALSE) return(0.0); if (num == 0.0) { SingularityErrorMessage(theEnv,"coth"); return(0.0); } else if (TestProximity(num,1e-25) == TRUE) { ArgumentOverflowErrorMessage(theEnv,"coth"); return(0.0); } return(1.0 / tanh(num)); }