static VALUE Elementary_multiply_err_e(VALUE self, VALUE x, VALUE dx, VALUE y, VALUE dy) { int ret; gsl_sf_result r; ret = gsl_sf_multiply_err_e(NUM2DBL(x), NUM2DBL(dx), NUM2DBL(y), NUM2DBL(dy), &r); return RESULT(&r); }
static VALUE rb_gsl_sf_multiply_err_e(VALUE obj, VALUE x, VALUE dx, VALUE y, VALUE dy) { gsl_sf_result *r; VALUE v; int status; Need_Float(x); Need_Float(y); Need_Float(dx); Need_Float(dy); v = Data_Make_Struct(cgsl_sf_result, gsl_sf_result, 0, free, r); status = gsl_sf_multiply_err_e(NUM2DBL(x), NUM2DBL(dx), NUM2DBL(y), NUM2DBL(dy), r); return v; }
int gsl_sf_bessel_IJ_taylor_e(const double nu, const double x, const int sign, const int kmax, const double threshold, gsl_sf_result * result ) { /* CHECK_POINTER(result) */ if(nu < 0.0 || x < 0.0) { DOMAIN_ERROR(result); } else if(x == 0.0) { if(nu == 0.0) { result->val = 1.0; result->err = 0.0; } else { result->val = 0.0; result->err = 0.0; } return GSL_SUCCESS; } else { gsl_sf_result prefactor; /* (x/2)^nu / Gamma(nu+1) */ gsl_sf_result sum; int stat_pre; int stat_sum; int stat_mul; if(nu == 0.0) { prefactor.val = 1.0; prefactor.err = 0.0; stat_pre = GSL_SUCCESS; } else if(nu < INT_MAX-1) { /* Separate the integer part and use * y^nu / Gamma(nu+1) = y^N /N! y^f / (N+1)_f, * to control the error. */ const int N = (int)floor(nu + 0.5); const double f = nu - N; gsl_sf_result poch_factor; gsl_sf_result tc_factor; const int stat_poch = gsl_sf_poch_e(N+1.0, f, &poch_factor); const int stat_tc = gsl_sf_taylorcoeff_e(N, 0.5*x, &tc_factor); const double p = pow(0.5*x,f); prefactor.val = tc_factor.val * p / poch_factor.val; prefactor.err = tc_factor.err * p / poch_factor.val; prefactor.err += fabs(prefactor.val) / poch_factor.val * poch_factor.err; prefactor.err += 2.0 * GSL_DBL_EPSILON * fabs(prefactor.val); stat_pre = GSL_ERROR_SELECT_2(stat_tc, stat_poch); } else { gsl_sf_result lg; const int stat_lg = gsl_sf_lngamma_e(nu+1.0, &lg); const double term1 = nu*log(0.5*x); const double term2 = lg.val; const double ln_pre = term1 - term2; const double ln_pre_err = GSL_DBL_EPSILON * (fabs(term1)+fabs(term2)) + lg.err; const int stat_ex = gsl_sf_exp_err_e(ln_pre, ln_pre_err, &prefactor); stat_pre = GSL_ERROR_SELECT_2(stat_ex, stat_lg); } /* Evaluate the sum. * [Abramowitz+Stegun, 9.1.10] * [Abramowitz+Stegun, 9.6.7] */ { const double y = sign * 0.25 * x*x; double sumk = 1.0; double term = 1.0; int k; for(k=1; k<=kmax; k++) { term *= y/((nu+k)*k); sumk += term; if(fabs(term/sumk) < threshold) break; } sum.val = sumk; sum.err = threshold * fabs(sumk); stat_sum = ( k >= kmax ? GSL_EMAXITER : GSL_SUCCESS ); } stat_mul = gsl_sf_multiply_err_e(prefactor.val, prefactor.err, sum.val, sum.err, result); return GSL_ERROR_SELECT_3(stat_mul, stat_pre, stat_sum); } }