Esempio n. 1
0
int gsl_sf_bessel_J1_e(const double x, gsl_sf_result * result)
{
  double y = fabs(x);

  /* CHECK_POINTER(result) */

  if(y == 0.0) {
    result->val = 0.0;
    result->err = 0.0;
    return GSL_SUCCESS;
  }
  else if(y < 2.0*GSL_DBL_MIN) {
    UNDERFLOW_ERROR(result);
  }
  else if(y < ROOT_EIGHT * GSL_SQRT_DBL_EPSILON) {
    result->val = 0.5*x;
    result->err = 0.0;
    return GSL_SUCCESS;
  }
  else if(y < 4.0) {
    gsl_sf_result c;
    cheb_eval_e(&bj1_cs, 0.125*y*y-1.0, &c);
    result->val = x * (0.25 + c.val);
    result->err = fabs(x * c.err);
    return GSL_SUCCESS;
  }
  else {
    /* Because the leading term in the phase is y,
     * which we assume is exactly known, the error
     * in the cos() evaluation is bounded.
     */
    const double z  = 32.0/(y*y) - 1.0;
    gsl_sf_result ca;
    gsl_sf_result ct;
    gsl_sf_result sp;
    const int stat_ca = cheb_eval_e(&_gsl_sf_bessel_amp_phase_bm1_cs,  z, &ca);
    const int stat_ct = cheb_eval_e(&_gsl_sf_bessel_amp_phase_bth1_cs, z, &ct);
    const int stat_sp = gsl_sf_bessel_sin_pi4_e(y, ct.val/y, &sp);
    const double sqrty = sqrt(y);
    const double ampl  = (0.75 + ca.val) / sqrty;
    result->val  = (x < 0.0 ? -ampl : ampl) * sp.val;
    result->err  = fabs(sp.val) * ca.err/sqrty + fabs(ampl) * sp.err;
    result->err += GSL_DBL_EPSILON * fabs(result->val);
    return GSL_ERROR_SELECT_3(stat_ca, stat_ct, stat_sp);
  }
}
int gsl_sf_bessel_Y0_e(const double x, gsl_sf_result * result)
{
    const double two_over_pi = 2.0/M_PI;
    const double xmax        = 1.0/GSL_DBL_EPSILON;

    /* CHECK_POINTER(result) */

    if (x <= 0.0) {
        DOMAIN_ERROR(result);
    }
    else if(x < 4.0) {
        gsl_sf_result J0;
        gsl_sf_result c;
        int stat_J0 = gsl_sf_bessel_J0_e(x, &J0);
        cheb_eval_e(&by0_cs, 0.125*x*x-1.0, &c);
        result->val = two_over_pi*(-M_LN2 + log(x))*J0.val + 0.375 + c.val;
        result->err = 2.0 * GSL_DBL_EPSILON * fabs(result->val) + c.err;
        return stat_J0;
    }
    else if(x < xmax) {
        /* Leading behaviour of phase is x, which is exact,
         * so the error is bounded.
         */
        const double z  = 32.0/(x*x) - 1.0;
        gsl_sf_result c1;
        gsl_sf_result c2;
        gsl_sf_result sp;
        const int stat_c1 = cheb_eval_e(&_gsl_sf_bessel_amp_phase_bm0_cs,  z, &c1);
        const int stat_c2 = cheb_eval_e(&_gsl_sf_bessel_amp_phase_bth0_cs, z, &c2);
        const int stat_sp = gsl_sf_bessel_sin_pi4_e(x, c2.val/x, &sp);
        const double sqrtx = sqrt(x);
        const double ampl  = (0.75 + c1.val) / sqrtx;
        result->val  = ampl * sp.val;
        result->err  = fabs(sp.val) * c1.err/sqrtx + fabs(ampl) * sp.err;
        result->err += 2.0 * GSL_DBL_EPSILON * fabs(result->val);
        return GSL_ERROR_SELECT_3(stat_sp, stat_c1, stat_c2);
    }
    else {
        UNDERFLOW_ERROR(result);
    }
}