### ----------------------------------------------------
### -- Math::Libgsl::Function
### -- Licenses: Artistic-2.0
### -- Authors: Fernando Santagata
### -- File: t/01-raw-function.rakutest
### ----------------------------------------------------
### -- Chunk 5 of 5
491577728, 10⁻¹⁵, 'l radial eigenfunction of the Laplacian on 3D hyperbolic space';
  ok gsl_sf_legendre_H3d_e(5, 1e0, 1e0, $res) == 0, 'l radial eigenfunction of the Laplacian on 3D hyperbolic space with error check';
  is-approx $res.val, 0.011498635037491577728, 10⁻¹⁵, 'l radial eigenfunction of the Laplacian on 3D hyperbolic space with error check: value';
  ok gsl_sf_legendre_H3d_array(10, 1e0, 3e0, $res_array) == 0, 'l radial eigenfunction of the Laplacian on 3D hyperbolic space array';
  is-approx $res_array[0], 0.014086820716211607, 10⁻¹⁵, 'l radial eigenfunction of the Laplacian on 3D hyperbolic space array: value';
}, 'raw - Legendre functions';

subtest {
  my gsl_sf_result $res .= new;
  is-approx gsl_sf_log(1.1e0), 0.09531017980432486004, :rel-tol(10⁻¹⁵), 'log(x)';
  ok gsl_sf_log_e(1.1e0, $res) == 0, 'log(x) with error check';
  is-approx $res.val, 0.09531017980432486004, :rel-tol(10⁻¹⁵), 'log(x) with error check: value';
  is-approx gsl_sf_log_abs(-1.1e0), 0.09531017980432486004, :rel-tol(10⁻¹⁵), 'log(|x|)';
  ok gsl_sf_log_abs_e(-1.1e0, $res) == 0, 'log(|x|) with error check';
  is-approx $res.val, 0.09531017980432486004, :rel-tol(10⁻¹⁵), 'log(|x|) with error check: value';
  my gsl_sf_result $lnr .= new;
  my gsl_sf_result $theta .= new;
  ok gsl_sf_complex_log_e(1e0, 1e0, $lnr, $theta) == 0, 'log(z) with error check';
  is-approx $lnr.val, 0.3465735902799726547, :rel-tol(10⁻¹⁵), 'log(z) with error check: lnr';
  is-approx $theta.val, 0.7853981633974483096, :rel-tol(10⁻¹⁵), 'log(z) with error check: theta';
  is-approx gsl_sf_log_1plusx(1e-4), 0.00009999500033330833533, :rel-tol(10⁻¹⁵), 'log(1+x)';
  ok gsl_sf_log_1plusx_e(1e-4, $res) == 0, 'log(1+x) with error check';
  is-approx $res.val, 0.00009999500033330833533, :rel-tol(10⁻¹⁵), 'log(1+x) with error check: value';
  is-approx gsl_sf_log_1plusx_mx(1e-4), -4.999666691664666833e-09, :rel-tol(10⁻¹⁵), 'log(1+x)-x';
  ok gsl_sf_log_1plusx_mx_e(1e-4, $res) == 0, 'log(1+x)-x with error check';
  is-approx $res.val, -4.999666691664666833e-09, :rel-tol(10⁻¹⁵), 'log(1+x)-x with error check: value';
}, 'raw - logarithms';

subtest {
  my gsl_sf_result $res .= new;
  is-approx gsl_sf_mathieu_a(2, 1.1e0), 4.440022293558291, :rel-tol(10⁻¹⁵), 'aₙ(q)';
  ok gsl_sf_mathieu_a_e(2, 1.1e0, $res) == 0, 'aₙ(q) with error check';
  is-approx $res.val, 4.440022293558291, :rel-tol(10⁻¹⁵), 'aₙ(q) with error check: value';
  is-approx gsl_sf_mathieu_b(2, 1.1e0), 3.8996898851752686, :rel-tol(10⁻¹⁵), 'bₙ(q)';
  ok gsl_sf_mathieu_b_e(2, 1.1e0, $res) == 0, 'bₙ(q) with error check';
  is-approx $res.val, 3.8996898851752686, :rel-tol(10⁻¹⁵), 'bₙ(q) with error check: value';
  my gsl_sf_mathieu_workspace $work;
  lives-ok { $work = gsl_sf_mathieu_alloc(6, 20e0) }, 'allocate workspace';
  my CArray[num64] $res_array .= new: 0e0 xx 6;
  ok gsl_sf_mathieu_a_array(0, 5, 0e0, $work, $res_array) == 0, 'aₙ(q) array';
  is-deeply $res_array.list, (0e0, 1e0, 4e0, 9e0, 16e0, 25e0), 'aₙ(q) array: values';
  ok gsl_sf_mathieu_b_array(0, 5, 0e0, $work, $res_array) == 0, 'bₙ(q) array';
  is-deeply $res_array.list, (0e0, 1e0, 4e0, 9e0, 16e0, 25e0), 'bₙ(q) array: values';
  is-approx gsl_sf_mathieu_ce(0, 0e0, 0e0), 0.7071067811865475, :rel-tol(10⁻¹⁵), 'ceₙ(q,x)';
  ok gsl_sf_mathieu_ce_e(0, 0e0, 0e0, $res) == 0, 'ceₙ(q,x) with error check';
  is-approx $res.val, 0.7071067811865475, :rel-tol(10⁻¹⁵), 'ceₙ(q,x) with error check: value';
  is-approx gsl_sf_mathieu_se(15, 0e0, π/2), -1, :rel-tol(10⁻¹⁵), 'seₙ(q,x)';
  ok gsl_sf_mathieu_se_e(15, 0e0, π/2, $res) == 0, 'seₙ(q,x) with error check';
  is-approx $res.val, -1, :rel-tol(10⁻¹⁵), 'seₙ(q,x) with error check: value';
  ok gsl_sf_mathieu_ce_array(0, 5, 0e0, π/2, $work, $res_array) == 0, 'ceₙ(q,x) array';
  is-deeply $res_array.list, (0.7071067811865475e0, 6.123233995736766e-17, -1e0, -1.8369701987210297e-16, 1e0, 3.061616997868383e-16), 'ceₙ(q,x) array: values';
  ok gsl_sf_mathieu_se_array(0, 5, 0e0, π/2, $work, $res_array) == 0, 'seₙ(q,x) array';
  is-deeply $res_array.list, (0e0, 1e0, 1.2246467991473532e-16, -1e0, -2.4492935982947064e-16, 1e0), 'seₙ(q,x) array: values';
  is-approx gsl_sf_mathieu_Mc(1, 0, 1e0, 0e0), 0.8447696705150902, :rel-tol(10⁻¹⁵), 'Mcʲₙ(q,x)';
  ok gsl_sf_mathieu_Mc_e(1, 0, 1e0, 0e0, $res) == 0, 'Mcʲₙ(q,x) with error check';
  is-approx $res.val, 0.8447696705150902, :rel-tol(10⁻¹⁵), 'Mcʲₙ(q,x) with error check: value';
  is-approx gsl_sf_mathieu_Ms(1, 0, 1e0, 0e0), 0, :rel-tol(10⁻¹⁵), 'Msʲₙ(q,x)';
  ok gsl_sf_mathieu_Ms_e(1, 0, 1e0, 0e0, $res) == 0, 'Msʲₙ(q,x) with error check';
  is-approx $res.val, 0, :rel-tol(10⁻¹⁵), 'Msʲₙ(q,x) with error check: value';
  ok gsl_sf_mathieu_Mc_array(1, 0, 5, 1e0, π/2, $work, $res_array) == 0, 'Mcʲₙ(q,x) array';
  is-deeply $res_array.list, (-0.3118830825472924e0, -0.401338211769362e0, 0.12436859192137752e0, 0.4930738160216151e0, 0.4754523550624284e0, 0.29643292798754495e0), 'Mcʲₙ(q,x) array: values';
  ok gsl_sf_mathieu_Ms_array(1, 0, 5, 1e0, π/2, $work, $res_array) == 0, 'Msʲₙ(q,x) array';
  is-deeply $res_array.list, (0e0, -0.3397911837218603e0, 0.1452203874466516e0, 0.49324139011869106e0, 0.4754148659557405e0, 0.2964318355087169e0), 'Msʲₙ(q,x) array: values';
  lives-ok { gsl_sf_mathieu_free($work) }, 'free workspace';
}, 'raw - Mathieu functions';

subtest {
  my gsl_sf_result $res .= new;
  is-approx gsl_sf_pow_int(2e0, 3), 8, :rel-tol(10⁻¹⁵), 'xⁿ';
  ok gsl_sf_pow_int_e(2e0, 3, $res) == 0, 'xⁿ with error check';
  is-approx $res.val, 8, :rel-tol(10⁻¹⁵), 'xⁿ with error check: value';
}, 'raw - Power functions';

subtest {
  my gsl_sf_result $res .= new;
  is-approx gsl_sf_psi_int(1), -0.57721566490153286060, :rel-tol(10⁻¹⁵), 'ψ(n)';
  ok gsl_sf_psi_int_e(1, $res) == 0, 'ψ(n) with error check';
  is-approx $res.val, -0.57721566490153286060, :rel-tol(10⁻¹⁵), 'ψ(n) with error check: value';
  is-approx gsl_sf_psi(1e0), -0.57721566490153286060, :rel-tol(10⁻¹⁵), 'ψ(x)';
  ok gsl_sf_psi_e(1e0, $res) == 0, 'ψ(x) with error check';
  is-approx $res.val, -0.57721566490153286060, :rel-tol(10⁻¹⁵), 'ψ(x) with error check: value';
  is-approx gsl_sf_psi_1piy(1e0), 0.09465032062247697727, :rel-tol(10⁻¹⁵), '𝕽[ψ(1+iy)]';
  ok gsl_sf_psi_1piy_e(1e0, $res) == 0, '𝕽[ψ(1+iy)] with error check';
  is-approx $res.val, 0.09465032062247697727, :rel-tol(10⁻¹⁵), '𝕽[ψ(1+iy)] with error check: value';
  is-approx gsl_sf_psi_1_int(1), 1.6449340668482264364, :rel-tol(10⁻¹⁵), 'ψ’(n)';
  ok gsl_sf_psi_1_int_e(1, $res) == 0, 'ψ’(n) with error check';
  is-approx $res.val, 1.6449340668482264364, :rel-tol(10⁻¹⁵), 'ψ’(n) with error check: value';
  is-approx gsl_sf_psi_1(1e0), 1.6449340668482264364, :rel-tol(10⁻¹⁵), 'ψ’(x)';
  ok gsl_sf_psi_1_e(1e0, $res) == 0, 'ψ’(x) with error check';
  is-approx $res.val, 1.6449340668482264364, :rel-tol(10⁻¹⁵), 'ψ’(x) with error check: value';
  is-approx gsl_sf_psi_n(1, 1e0), 1.6449340668482264364, :rel-tol(10⁻¹⁵), 'ψⁿ(n)';
  ok gsl_sf_psi_n_e(1, 1e0, $res) == 0, 'ψⁿ(n) with error check';
  is-approx $res.val, 1.6449340668482264364, :rel-tol(10⁻¹⁵), 'ψⁿ(n) with error check: value';
}, 'raw - Psi functions';

subtest {
  my gsl_sf_result $res .= new;
  is-approx gsl_sf_synchrotron_1(1e0), 0.651422815355364504, 10⁻¹⁵, 'First synchrotron function';
  ok gsl_sf_synchrotron_1_e(1e0, $res) == 0, 'First synchrotron function with error check';
  is-approx $res.val, 0.651422815355364504, 10⁻¹⁵, 'First synchrotron function with error check: value';
  is-approx gsl_sf_synchrotron_2(1e0), 0.49447506210420666, :rel-tol(10⁻¹⁵), 'Second synchrotron function';
  ok gsl_sf_synchrotron_2_e(1e0, $res) == 0, 'Second synchrotron function with error check';
  is-approx $res.val, 0.49447506210420666, :rel-tol(10⁻¹⁵), 'Second synchrotron function with error check: value';
}, 'raw - Synchrotron functions';

subtest {
  my gsl_sf_result $res .= new;
  is-approx gsl_sf_transport_2(1e0), 0.97303256135517012845, 10⁻¹⁵, 'J(2,x)';
  ok gsl_sf_transport_2_e(1e0, $res) == 0, 'J(2,x) with error check';
  is-approx $res.val, 0.97303256135517012845, 10⁻¹⁵, 'J(2,x) with error check: value';
  is-approx gsl_sf_transport_3(1e0), 0.479841006572417499939, 10⁻¹⁵, 'J(3,x)';
  ok gsl_sf_transport_3_e(1e0, $res) == 0, 'J(3,x) with error check';
  is-approx $res.val, 0.479841006572417499939, 10⁻¹⁵, 'J(3,x) with error check: value';
  is-approx gsl_sf_transport_4(1e0), 0.31724404523442648241, 10⁻¹⁵, 'J(4,x)';
  ok gsl_sf_transport_4_e(1e0, $res) == 0, 'J(4,x) with error check';
  is-approx $res.val, 0.31724404523442648241, 10⁻¹⁵, 'J(4,x) with error check: value';
  is-approx gsl_sf_transport_5(1e0), 0.236615879239094789259153, 10⁻¹⁵, 'J(5,x)';
  ok gsl_sf_transport_5_e(1e0, $res) == 0, 'J(5,x) with error check';
  is-approx $res.val, 0.236615879239094789259153, 10⁻¹⁵, 'J(5,x) with error check: value';
}, 'raw - Transport functions';

subtest {
  my gsl_sf_result $res .= new;
  is-approx gsl_sf_sin(1e0), 0.8414709848078965067, 10⁻¹⁵, 'sin(x)';
  ok gsl_sf_sin_e(1e0, $res) == 0, 'sin(x) with error check';
  is-approx $res.val, 0.8414709848078965067, 10⁻¹⁵, 'sin(x) with error check: value';
  is-approx gsl_sf_cos(1e0), 0.5403023058681397174, 10⁻¹⁵, 'cos(x)';
  ok gsl_sf_cos_e(1e0, $res) == 0, 'cos(x) with error check';
  is-approx $res.val, 0.5403023058681397174, 10⁻¹⁵, 'cos(x) with error check: value';
  is-approx gsl_sf_hypot(3e0, 4e0), 5, 10⁻¹⁵, '√x²+y²';
  ok gsl_sf_hypot_e(3e0, 4e0, $res) == 0, '√x²+y² with error check';
  is-approx $res.val, 5, 10⁻¹⁵, '√x²+y² with error check: value';
  is-approx gsl_sf_sinc(80.5e0), 0.0039541600768172754, 10⁻¹⁵, 'sinc(x)';
  ok gsl_sf_sinc_e(80.5e0, $res) == 0, 'sinc(x) with error check';
  is-approx $res.val, 0.0039541600768172754, 10⁻¹⁵, 'sinc(x) with error check: value';
  my gsl_sf_result $zr .= new;
  my gsl_sf_result $zi .= new;
  ok gsl_sf_complex_sin_e(1e0, 5e0, $zr, $zi) == 0, 'sin(z) with error check';
  is-approx $zr.val, 62.44551846769653403, 10⁻¹⁵, 'sin(z) with error check: re';
  is-approx $zi.val, 40.09216577799840254, 10⁻¹⁵, 'sin(z) with error check: im';
  ok gsl_sf_complex_cos_e(1e0, 5e0, $zr, $zi) == 0, 'cos(z) with error check';
  is-approx $zr.val, 40.09580630629882573, :rel-tol(10⁻¹⁵), 'cos(z) with error check: re';
  is-approx $zi.val, -62.43984868079963017, :rel-tol(10⁻¹⁵), 'cos(z) with error check: im';
  ok gsl_sf_complex_logsin_e(5e0, 5e0, $zr, $zi) == 0, 'log(sin(z)) with error check';
  is-approx $zr.val, 4.3068909128079757420, 10⁻¹⁵, 'log(sin(z)) with error check: re';
  is-approx $zi.val, 2.8540063315538773952, 10⁻¹⁵, 'log(sin(z)) with error check: im';
  is-approx gsl_sf_lnsinh(1e0), 0.16143936157119563361, 10⁻¹⁵, 'log(sinh(x))';
  ok gsl_sf_lnsinh_e(1e0, $res) == 0, 'log(sinh(x)) with error check';
  is-approx $res.val, 0.16143936157119563361, 10⁻¹⁵, 'log(sinh(x)) with error check: value';
  is-approx gsl_sf_lncosh(1e0), 0.4337808304830271870, 10⁻¹⁵, 'log(cosh(x))';
  ok gsl_sf_lncosh_e(1e0, $res) == 0, 'log(cosh(x)) with error check';
  is-approx $res.val, 0.4337808304830271870, 10⁻¹⁵, 'log(cosh(x)) with error check: value';
  ok gsl_sf_polar_to_rect(10e0, π/6, $zr, $zi) == 0, 'polar to rect';
  is-approx $zr.val, (10e0 * sqrt(3) / 2e0), :rel-tol(10⁻¹⁵), 'polar to rect: value';
  is-approx $zi.val, 10e0 * .5e0, :rel-tol(10⁻¹⁵), 'polar to rect: value';
  ok gsl_sf_rect_to_polar(10e0, 6e0, $zr, $zi) == 0, 'rect to polar';
  is-approx $zr.val, 11.6619037896906, :rel-tol(10⁻¹⁵), 'rect to polar: value';
  is-approx $zi.val, 0.5404195002705842, :rel-tol(10⁻¹⁵), 'rect to polar: value';
  is-approx gsl_sf_angle_restrict_symm(1e9), 0.5773954235013851694, 10⁻¹⁵, 'θ in [-π,π)';
  my num64 $theta = 1e9;
  ok gsl_sf_angle_restrict_symm_e($theta) == 0, 'θ in [-π,π) with error check';
  is-approx $theta, 0.5773954235013851694, 10⁻¹⁵, 'θ in [-π,π) with error check: value';
  is-approx gsl_sf_angle_restrict_pos(1e9), 0.5773954235013851694, 10⁻¹⁵, 'θ in [-0,2π)';
  $theta = 1e9;
  ok gsl_sf_angle_restrict_pos_e($theta) == 0, 'θ in [-0,2π) with error check';
  is-approx $theta, 0.5773954235013851694, 10⁻¹⁵, 'θ in [-0,2π) with error check: value';
  ok gsl_sf_sin_err_e(1e0, 1e-9, $res) == 0, 'sin(x±dx) with error check';
  is-approx $res.val, 0.8414709848078965067, 10⁻¹⁵, 'sin(x±dx) with error check: value';
  ok gsl_sf_cos_err_e(1e0, 1e-9, $res) == 0, 'cos(x±dx) with error check';
  is-approx $res.val, 0.5403023058681397174, 10⁻¹⁵, 'cos(x±dx) with error check: value';
}, 'raw - Trigonometric functions';

subtest {
  my gsl_sf_result $res .= new;
  is-approx gsl_sf_zeta_int(5), 1.0369277551433699263313655, 10⁻¹⁵, 'ζ(n)';
  ok gsl_sf_zeta_int_e(5, $res) == 0, 'ζ(n) with error check';
  is-approx $res.val, 1.0369277551433699263313655, 10⁻¹⁵, 'ζ(n) with error check: value';
  is-approx gsl_sf_zeta(5e0), 1.0369277551433699263313655, 10⁻¹⁵, 'ζ(x)';
  ok gsl_sf_zeta_e(5e0, $res) == 0, 'ζ(x) with error check';
  is-approx $res.val, 1.0369277551433699263313655, 10⁻¹⁵, 'ζ(x) with error check: value';
  is-approx gsl_sf_zetam1_int(5), 0.0369277551433699263313655, 10⁻¹⁵, 'ζ(n)-1';
  ok gsl_sf_zetam1_int_e(5, $res) == 0, 'ζ(n)-1 with error check';
  is-approx $res.val, 0.0369277551433699263313655, 10⁻¹⁵, 'ζ(n)-1 with error check: value';
  is-approx gsl_sf_zetam1(5e0), 0.0369277551433699263313655, 10⁻¹⁵, 'ζ(x)-1';
  ok gsl_sf_zetam1_e(5e0, $res) == 0, 'ζ(x)-1 with error check';
  is-approx $res.val, 0.0369277551433699263313655, 10⁻¹⁵, 'ζ(x)-1 with error check: value';
  is-approx gsl_sf_hzeta(5e0, 1e0), 1.0369277551433699263, 10⁻¹⁵, 'ζ(s,q)';
  ok gsl_sf_hzeta_e(5e0, 1e0, $res) == 0, 'ζ(s,q) with error check';
  is-approx $res.val, 1.0369277551433699263, 10⁻¹⁵, 'ζ(s,q) with error check: value';
  is-approx gsl_sf_eta_int(5), 0.9721197704469093059, 10⁻¹⁵, 'η(n)';
  ok gsl_sf_eta_int_e(5, $res) == 0, 'η(n) with error check';
  is-approx $res.val, 0.9721197704469093059, 10⁻¹⁵, 'η(n) with error check: value';
  is-approx gsl_sf_eta(5e0), 0.9721197704469093059, 10⁻¹⁵, 'η(x)';
  ok gsl_sf_eta_e(5e0, $res) == 0, 'η(x) with error check';
  is-approx $res.val, 0.9721197704469093059, 10⁻¹⁵, 'η(x) with error check: value';
}, 'raw - Zeta functions';

done-testing;


