### ----------------------------------------------------
### -- Math::SpecialFunctions
### -- Licenses: Artistic-2.0
### -- Authors: Anton Antonov
### -- File: t/04-gamma.rakutest
### ----------------------------------------------------
use v6.d;
use Test;

#use lib <. lib>;

use Math::SpecialFunctions;

# See https://en.wikipedia.org/wiki/Gamma_function#Particular_values

my $abs-tol = 1.0e-13;

## 1
subtest {
    is-approx Γ(-3 / 2), 4 * sqrt(pi) / 3, 'Γ(-3/2)', :$abs-tol;

    is-approx Γ(-1 / 2), -2 * sqrt(pi), 'Γ(-1/2)', :$abs-tol;

    is-approx Γ(1 / 2), sqrt(pi), 'Γ(1/2)', :$abs-tol;

    is-approx Γ(1), 1, 'Γ(1)', :$abs-tol;

    is-approx Γ(3 / 2), sqrt(pi) / 2, 'Γ(3/2)', :$abs-tol;

    is-approx Γ(2), 1, 'Γ(2)', :$abs-tol;

    is-approx Γ(5 / 2), 3 * sqrt(pi) / 4, 'Γ(5/2)', :$abs-tol;

    is-approx Γ(3), 2, 'Γ(3)', :$abs-tol;

    is-approx Γ(7 / 2), 15 * sqrt(pi) / 8, 'Γ(7/2)', :$abs-tol;

    is-approx Γ(4), 6, 'Γ(4)', :$abs-tol;
}, 'Gamma function';


## 2
subtest {
    isa-ok euler-gamma, Numeric:D;
    isa-ok euler-gamma(:10precision), Numeric:D;

    # From Wolfram Language:
    # In[200]:= N[EulerGamma, 50]
    # Out[200]= 0.57721566490153286060651209008240243104215933593992
    my $eg = 0.57721566490153286060651209008240243104215933593992;
    is-approx euler-gamma(:10prec), $eg, $abs-tol;
    is-approx euler-gamma(:40p), $eg, 10e-40;
}, "Euler's gamma";

done-testing;



