### ----------------------------------------------------
### -- Math::Libgsl::Function
### -- Licenses: Artistic-2.0
### -- Authors: Fernando Santagata
### -- File: t/02-function.rakutest
### ----------------------------------------------------
### -- Chunk 5 of 5
060, :rel-tol(10⁻¹⁵), 'ψ(x) with error check: value';
  is-approx psi1piy(1), 0.09465032062247697727, :rel-tol(10⁻¹⁵), '𝕽[ψ(1+iy)]';
  lives-ok { ($val, $err) = psi1piy-e(1) }, '𝕽[ψ(1+iy)] with error check';
  is-approx $val, 0.09465032062247697727, :rel-tol(10⁻¹⁵), '𝕽[ψ(1+iy)] with error check: value';
  is-approx psi1-int(1), 1.6449340668482264364, :rel-tol(10⁻¹⁵), 'ψ’(n)';
  lives-ok { ($val, $err) = psi1-int-e(1) }, 'ψ’(n) with error check';
  is-approx $val, 1.6449340668482264364, :rel-tol(10⁻¹⁵), 'ψ’(n) with error check: value';
  is-approx psi1(1), 1.6449340668482264364, :rel-tol(10⁻¹⁵), 'ψ’(x)';
  lives-ok { ($val, $err) = psi1-e(1) }, 'ψ’(x) with error check';
  is-approx $val, 1.6449340668482264364, :rel-tol(10⁻¹⁵), 'ψ’(x) with error check: value';
  is-approx psin(1, 1), 1.6449340668482264364, :rel-tol(10⁻¹⁵), 'ψⁿ(n)';
  lives-ok { ($val, $err) = psin-e(1, 1) }, 'ψⁿ(n) with error check';
  is-approx $val, 1.6449340668482264364, :rel-tol(10⁻¹⁵), 'ψⁿ(n) with error check: value';
}, 'Psi functions';

subtest {
  my ($val, $err);
  is-approx synchrotron1(1), 0.651422815355364504, 10⁻¹⁵, 'First synchrotron function';
  lives-ok { ($val, $err) = synchrotron1-e(1) }, 'First synchrotron function with error check';
  is-approx $val, 0.651422815355364504, 10⁻¹⁵, 'First synchrotron function with error check: value';
  is-approx synchrotron2(1), 0.49447506210420666, :rel-tol(10⁻¹⁵), 'Second synchrotron function';
  lives-ok { ($val, $err) = synchrotron2-e(1) }, 'Second synchrotron function with error check';
  is-approx $val, 0.49447506210420666, :rel-tol(10⁻¹⁵), 'Second synchrotron function with error check: value';
}, 'Synchrotron functions';

subtest {
  my ($val, $err);
  is-approx transport2(1), 0.97303256135517012845, 10⁻¹⁵, 'J(2,x)';
  lives-ok { ($val, $err) = transport2-e(1) }, 'J(2,x) with error check';
  is-approx $val, 0.97303256135517012845, 10⁻¹⁵, 'J(2,x) with error check: value';
  is-approx transport3(1), 0.479841006572417499939, 10⁻¹⁵, 'J(3,x)';
  lives-ok { ($val, $err) = transport3-e(1) }, 'J(3,x) with error check';
  is-approx $val, 0.479841006572417499939, 10⁻¹⁵, 'J(3,x) with error check: value';
  is-approx transport4(1), 0.31724404523442648241, 10⁻¹⁵, 'J(4,x)';
  lives-ok { ($val, $err) = transport4-e(1) }, 'J(4,x) with error check';
  is-approx $val, 0.31724404523442648241, 10⁻¹⁵, 'J(4,x) with error check: value';
  is-approx transport5(1), 0.236615879239094789259153, 10⁻¹⁵, 'J(5,x)';
  lives-ok { ($val, $err) = transport5-e(1) }, 'J(5,x) with error check';
  is-approx $val, 0.236615879239094789259153, 10⁻¹⁵, 'J(5,x) with error check: value';
}, 'Transport functions';

subtest {
  my ($val, $err);
  is-approx gsl-sin(1), 0.8414709848078965067, 10⁻¹⁵, 'sin(x)';
  lives-ok { ($val, $err) = gsl-sin-e(1) }, 'sin(x) with error check';
  is-approx $val, 0.8414709848078965067, 10⁻¹⁵, 'sin(x) with error check: value';
  is-approx gsl-cos(1), 0.5403023058681397174, 10⁻¹⁵, 'cos(x)';
  lives-ok { ($val, $err) = gsl-cos-e(1) }, 'cos(x) with error check';
  is-approx $val, 0.5403023058681397174, 10⁻¹⁵, 'cos(x) with error check: value';
  is-approx gsl-hypot(3, 4), 5, 10⁻¹⁵, '√x²+y²';
  lives-ok { ($val, $err) = gsl-hypot-e(3, 4) }, '√x²+y² with error check';
  is-approx $val, 5, 10⁻¹⁵, '√x²+y² with error check: value';
  is-approx gsl-sinc(80.5), 0.0039541600768172754, 10⁻¹⁵, 'sinc(x)';
  lives-ok { ($val, $err) = gsl-sinc-e(80.5) }, 'sinc(x) with error check';
  is-approx $val, 0.0039541600768172754, 10⁻¹⁵, 'sinc(x) with error check: value';
  my ($rval, $rerr, $ival, $ierr);
  lives-ok { ($rval, $rerr, $ival, $ierr) = gsl-complex-sin-e(1, 5) }, 'sin(z) with error check';
  is-approx $rval, 62.44551846769653403, 10⁻¹⁵, 'sin(z) with error check: re';
  is-approx $ival, 40.09216577799840254, 10⁻¹⁵, 'sin(z) with error check: im';
  lives-ok { ($rval, $rerr, $ival, $ierr) = gsl-complex-cos-e(1, 5) }, 'cos(z) with error check';
  is-approx $rval, 40.09580630629882573, :rel-tol(10⁻¹⁵), 'cos(z) with error check: re';
  is-approx $ival, -62.43984868079963017, :rel-tol(10⁻¹⁵), 'cos(z) with error check: im';
  lives-ok { ($rval, $rerr, $ival, $ierr) = gsl-complex-logsin-e(5, 5) }, 'log(sin(z)) with error check';
  is-approx $rval, 4.3068909128079757420, 10⁻¹⁵, 'log(sin(z)) with error check: re';
  is-approx $ival, 2.8540063315538773952, 10⁻¹⁵, 'log(sin(z)) with error check: im';
  is-approx gsl-lnsinh(1), 0.16143936157119563361, 10⁻¹⁵, 'log(sinh(x))';
  lives-ok { ($val, $err) = gsl-lnsinh-e(1) }, 'log(sinh(x)) with error check';
  is-approx $val, 0.16143936157119563361, 10⁻¹⁵, 'log(sinh(x)) with error check: value';
  is-approx gsl-lncosh(1), 0.4337808304830271870, 10⁻¹⁵, 'log(cosh(x))';
  lives-ok { ($val, $err) = gsl-lncosh-e(1) }, 'log(cosh(x)) with error check';
  is-approx $val, 0.4337808304830271870, 10⁻¹⁵, 'log(cosh(x)) with error check: value';
  my ($xval, $xerr, $yval, $yerr);
  lives-ok { ($xval, $xerr, $yval, $yerr) = polar-to-rect(10, π/6) }, 'polar to rect';
  is-approx $xval, (10 * sqrt(3) / 2), :rel-tol(10⁻¹⁵), 'polar to rect: value';
  is-approx $yval, 5, :rel-tol(10⁻¹⁵), 'polar to rect: value';
  dies-ok { ($xval, $xerr, $yval, $yerr) = polar-to-rect(10, 3 * π) }, 'polar to rect dies when theta > π';
  my ($thetaval, $thetaerr);
  lives-ok { ($rval, $rerr, $thetaval, $thetaerr) = rect-to-polar(10, 6) }, 'rect to polar';
  is-approx $rval, 11.6619037896906, :rel-tol(10⁻¹⁵), 'rect to polar: value';
  is-approx $thetaval, 0.5404195002705842, :rel-tol(10⁻¹⁵), 'rect to polar: value';
  is-approx angle-restrict-symm(1e9), 0.5773954235013851694, 10⁻¹⁵, 'θ in [-π,π)';
  lives-ok { $thetaval = angle-restrict-symm-e(1e9) }, 'θ in [-π,π) with error check';
  is-approx $thetaval, 0.5773954235013851694, 10⁻¹⁵, 'θ in [-π,π) with error check: value';
  is-approx angle-restrict-pos(1e9), 0.5773954235013851694, 10⁻¹⁵, 'θ in [-0,2π)';
  lives-ok { $thetaval = angle-restrict-pos-e(1e9) }, 'θ in [-0,2π) with error check';
  is-approx $thetaval, 0.5773954235013851694, 10⁻¹⁵, 'θ in [-0,2π) with error check: value';
  lives-ok { ($val, $err) = gsl-sin-err-e(1, 1e-9) }, 'sin(x±dx) with error check';
  is-approx $val, 0.8414709848078965067, 10⁻¹⁵, 'sin(x±dx) with error check: value';
  lives-ok { ($val, $err) = gsl-cos-err-e(1, 1e-9) }, 'cos(x±dx) with error check';
  is-approx $val, 0.5403023058681397174, 10⁻¹⁵, 'cos(x±dx) with error check: value';
}, 'Trigonometric functions';

subtest {
  my ($val, $err);
  is-approx zeta-int(5), 1.0369277551433699263313655, 10⁻¹⁵, 'ζ(n)';
  lives-ok { ($val, $err) = zeta-int-e(5) }, 'ζ(n) with error check';
  is-approx $val, 1.0369277551433699263313655, 10⁻¹⁵, 'ζ(n) with error check: value';
  is-approx zeta(5), 1.0369277551433699263313655, 10⁻¹⁵, 'ζ(x)';
  lives-ok { ($val, $err) = zeta-e(5) }, 'ζ(x) with error check';
  is-approx $val, 1.0369277551433699263313655, 10⁻¹⁵, 'ζ(x) with error check: value';
  is-approx zetam1-int(5), 0.0369277551433699263313655, 10⁻¹⁵, 'ζ(n)-1';
  lives-ok { ($val, $err) = zetam1-int-e(5) }, 'ζ(n)-1 with error check';
  is-approx $val, 0.0369277551433699263313655, 10⁻¹⁵, 'ζ(n)-1 with error check: value';
  is-approx zetam1(5), 0.0369277551433699263313655, 10⁻¹⁵, 'ζ(x)-1';
  lives-ok { ($val, $err) = zetam1-e(5) }, 'ζ(x)-1 with error check';
  is-approx $val, 0.0369277551433699263313655, 10⁻¹⁵, 'ζ(x)-1 with error check: value';
  is-approx hzeta(5, 1), 1.0369277551433699263, 10⁻¹⁵, 'ζ(s,q)';
  lives-ok { ($val, $err) = hzeta-e(5, 1) }, 'ζ(s,q) with error check';
  is-approx $val, 1.0369277551433699263, 10⁻¹⁵, 'ζ(s,q) with error check: value';
  is-approx eta-int(5), 0.9721197704469093059, 10⁻¹⁵, 'η(n)';
  lives-ok { ($val, $err) = eta-int-e(5) }, 'η(n) with error check';
  is-approx $val, 0.9721197704469093059, 10⁻¹⁵, 'η(n) with error check: value';
  is-approx eta(5), 0.9721197704469093059, 10⁻¹⁵, 'η(x)';
  lives-ok { ($val, $err) = eta-e(5) }, 'η(x) with error check';
  is-approx $val, 0.9721197704469093059, 10⁻¹⁵, 'η(x) with error check: value';
}, 'Zeta functions';

done-testing;


