Alex Bikfalvi
SimStream Documentation
Exp.cpp
00001 #include "Headers.h" 00002 #include "Exp.h" 00003 00004 int ExpMultErr(const double x, const double dx, const double y, const double dy, MathResult * result) 00005 { 00006 const double ay = fabs(y); 00007 00008 if(y == 0.0) 00009 { 00010 result->val = 0.0; 00011 result->err = fabs(dy * exp(x)); 00012 return MATH_SUCCESS; 00013 } 00014 else if((x < 0.5*MATH_LOG_DBL_MAX && x > 0.5*MATH_LOG_DBL_MIN) && (ay < 0.8*MATH_SQRT_DBL_MAX && ay > 1.2*MATH_SQRT_DBL_MIN)) 00015 { 00016 double ex = exp(x); 00017 result->val = y * ex; 00018 result->err = ex * (fabs(dy) + fabs(y*dx)); 00019 result->err += 2.0 * MATH_DBL_EPSILON * fabs(result->val); 00020 return MATH_SUCCESS; 00021 } 00022 else 00023 { 00024 const double ly = log(ay); 00025 const double lnr = x + ly; 00026 00027 if(lnr > MATH_LOG_DBL_MAX - 0.01) 00028 { 00029 OVERFLOW_ERROR(result); 00030 } 00031 else if(lnr < MATH_LOG_DBL_MIN + 0.01) 00032 { 00033 UNDERFLOW_ERROR(result); 00034 } 00035 else 00036 { 00037 const double sy = MATH_SIGN(y); 00038 const double M = floor(x); 00039 const double N = floor(ly); 00040 const double a = x - M; 00041 const double b = ly - N; 00042 const double eMN = exp(M+N); 00043 const double eab = exp(a+b); 00044 result->val = sy * eMN * eab; 00045 result->err = eMN * eab * 2.0*MATH_DBL_EPSILON; 00046 result->err += eMN * eab * fabs(dy/y); 00047 result->err += eMN * eab * fabs(dx); 00048 return MATH_SUCCESS; 00049 } 00050 } 00051 }
Last updated: February 8, 2011