[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Help-gsl] bug in gsl_sf_lncosh?
From: |
Maximilian Treiber |
Subject: |
[Help-gsl] bug in gsl_sf_lncosh? |
Date: |
Wed, 13 Jul 2011 11:54:42 +0200 |
User-agent: |
Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.17) Gecko/20110424 Thunderbird/3.1.10 |
Hi List,
the function f(x)=ln(cosh(x)) is obviously symmetric, ie f(x)=f(-x),
right?
The current implementation in gsl seems to be incorrect for negative
values:
=== from version 1.5 ===
int gsl_sf_lncosh_e(const double x, gsl_sf_result * result)
{
/* CHECK_POINTER(result) */
if(fabs(x) < 1.0) {
double eps;
cosh_m1_series(x, &eps);
return gsl_sf_log_1plusx_e(eps, result);
}
else if(x < -0.5*GSL_LOG_DBL_EPSILON) {
result->val = x + log(0.5*(1.0 + exp(-2.0*x)));
result->err = 2.0 * GSL_DBL_EPSILON * fabs(result->val);
return GSL_SUCCESS;
}
else {
result->val = -M_LN2 + x;
result->err = 2.0 * GSL_DBL_EPSILON * fabs(result->val);
return GSL_SUCCESS;
}
}
===
The second elseif is met for large negative numbers, while the
correct asymptotic limit would be "f(x->-inf) = |x|-ln(2)".
Replacing x by fabs(x) everywhere should fix the problem ...
Regards
Max
- [Help-gsl] bug in gsl_sf_lncosh?,
Maximilian Treiber <=