int gsl_sf_complex_psi_e( const double x, const double y, gsl_sf_result * result_re, gsl_sf_result * result_im ) { if(x >= 0.0) { gsl_complex z = gsl_complex_rect(x, y); return psi_complex_rhp(z, result_re, result_im); } else { /* reflection formula [Abramowitz+Stegun, 6.3.7] */ gsl_complex z = gsl_complex_rect(x, y); gsl_complex omz = gsl_complex_rect(1.0 - x, -y); gsl_complex zpi = gsl_complex_mul_real(z, M_PI); gsl_complex cotzpi = gsl_complex_cot(zpi); int ret_val = psi_complex_rhp(omz, result_re, result_im); if(GSL_IS_REAL(GSL_REAL(cotzpi)) && GSL_IS_REAL(GSL_IMAG(cotzpi))) { result_re->val -= M_PI * GSL_REAL(cotzpi); result_im->val -= M_PI * GSL_IMAG(cotzpi); return ret_val; } else { GSL_ERROR("singularity", GSL_EDOM); } } }
static double interpolate(double a, double fa, double fpa, double b, double fb, double fpb, double xmin, double xmax, int order) { /* * Map [a,b] to [0,1] */ double z, alpha, zmin, zmax; zmin = (xmin - a) / (b - a); zmax = (xmax - a) / (b - a); if (zmin > zmax) { double tmp = zmin; zmin = zmax; zmax = tmp; }; if (order > 2 && GSL_IS_REAL(fpb)) { z = interp_cubic(fa, fpa * (b - a), fb, fpb * (b - a), zmin, zmax); } else { z = interp_quad(fa, fpa * (b - a), fb, zmin, zmax); } alpha = a + z * (b - a); return alpha; }