|
1 | 1 | @testset "incomplete gamma ratios" begin
|
2 | 2 | #Computed using Wolframalpha gamma(a,x)/gamma(a) ~ gamma_q(a,x,0) function.
|
3 |
| - @test gamma_inc(10,10,0)[2] ≈ 0.45792971447185221 |
4 |
| - @test gamma_inc(1,1,0)[2] ≈ 0.3678794411714423216 |
5 |
| - @test gamma_inc(0.5,0.5,0)[2] ≈ 0.31731050786291410 |
6 |
| - @test gamma_inc(BigFloat(30.5),BigFloat(30.5),0)[2] ≈ parse(BigFloat,"0.47591691193354987004") rtol=eps() |
7 |
| - @test gamma_inc(5.5,0.5,0)[2] ≈ 0.9999496100513121669 |
8 |
| - @test gamma_inc(0.5,7.4,0)[2] ≈ 0.0001195355018130302 |
9 |
| - @test gamma_inc(0.5,0.22,0)[2] ≈ 0.507122455359825146 |
10 |
| - @test gamma_inc(0.5,0.8,0)[2] ≈ 0.20590321073206830887 |
11 |
| - @test gamma_inc(11.5,0.5,0)[2] ≈ 0.999999999998406112 |
12 |
| - @test gamma_inc(0.19,0.99,0)[2] ≈ 0.050147247342905857 |
13 |
| - @test gamma_inc(0.9999,0.9999,0)[2] ≈ 0.3678730556923103 |
14 |
| - @test gamma_inc(24,23.9999999999,0)[2] ≈ 0.472849720555859138 |
15 |
| - @test gamma_inc(0.5,0.55,0)[2] ≈ 0.29426610430496289 |
16 |
| - @test gamma_inc(Float32(0.5),Float32(0.55),0)[2] ≈ Float32(gamma_inc(0.5,0.55,0)[2]) |
17 |
| - @test gamma_inc(Float16(0.5),Float16(0.55),0)[2] ≈ Float16(gamma_inc(0.5,0.55,0)[2]) |
18 |
| - @test gamma_inc(30,29.99999,0)[2] ≈ 0.475717712451705704 |
19 |
| - @test gamma_inc(30,29.9,0)[2] ≈ 0.482992166284958565 |
20 |
| - @test gamma_inc(10,0.0001,0)[2] ≈ 1.0000 |
21 |
| - @test gamma_inc(0.0001,0.0001,0)[2] ≈ 0.000862958131006599 |
22 |
| - @test gamma_inc(0.0001,10.5,0)[1] ≈ 0.999999999758896146 |
23 |
| - @test gamma_inc(1,1,0)[1] ≈ 0.63212055882855768 |
24 |
| - @test gamma_inc(13,15.1,0)[2] ≈ 0.25940814264863701 |
25 |
| - @test gamma_inc(0.6,1.3,0)[2] ≈ 0.136458554006505355 |
26 |
| - @test gamma_inc((100),(80),0)[2] ≈ 0.9828916869648668 |
| 3 | + @test gamma_inc(10,10)[2] ≈ 0.45792971447185221 |
| 4 | + @test gamma_inc(1,1)[2] ≈ 0.3678794411714423216 |
| 5 | + @test gamma_inc(0.5,0.5)[2] ≈ 0.31731050786291410 |
| 6 | + @test gamma_inc(BigFloat(30.5),BigFloat(30.5))[2] ≈ parse(BigFloat,"0.47591691193354987004") rtol=eps() |
| 7 | + @test gamma_inc(5.5,0.5)[2] ≈ 0.9999496100513121669 |
| 8 | + @test gamma_inc(0.5,7.4)[2] ≈ 0.0001195355018130302 |
| 9 | + @test gamma_inc(0.5,0.22)[2] ≈ 0.507122455359825146 |
| 10 | + @test gamma_inc(0.5,0.8)[2] ≈ 0.20590321073206830887 |
| 11 | + @test gamma_inc(11.5,0.5)[2] ≈ 0.999999999998406112 |
| 12 | + @test gamma_inc(0.19,0.99)[2] ≈ 0.050147247342905857 |
| 13 | + @test gamma_inc(0.9999,0.9999)[2] ≈ 0.3678730556923103 |
| 14 | + @test gamma_inc(24,23.9999999999)[2] ≈ 0.472849720555859138 |
| 15 | + @test gamma_inc(0.5,0.55)[2] ≈ 0.29426610430496289 |
| 16 | + @test gamma_inc(Float32(0.5),Float32(0.55))[2] ≈ Float32(gamma_inc(0.5,0.55)[2]) |
| 17 | + @test gamma_inc(Float16(0.5),Float16(0.55))[2] ≈ Float16(gamma_inc(0.5,0.55)[2]) |
| 18 | + @test gamma_inc(30,29.99999)[2] ≈ 0.475717712451705704 |
| 19 | + @test gamma_inc(30,29.9)[2] ≈ 0.482992166284958565 |
| 20 | + @test gamma_inc(10,0.0001)[2] ≈ 1.0000 |
| 21 | + @test gamma_inc(0.0001,0.0001)[2] ≈ 0.000862958131006599 |
| 22 | + @test gamma_inc(0.0001,10.5)[1] ≈ 0.999999999758896146 |
| 23 | + @test gamma_inc(1,1)[1] ≈ 0.63212055882855768 |
| 24 | + @test gamma_inc(13,15.1)[2] ≈ 0.25940814264863701 |
| 25 | + @test gamma_inc(0.6,1.3)[2] ≈ 0.136458554006505355 |
| 26 | + @test gamma_inc((100),(80))[2] ≈ 0.9828916869648668 |
27 | 27 | @test gamma_inc((100),(80),1)[2] ≈ 0.9828916869
|
28 | 28 | @test Float16(gamma_inc((100),(80),2)[2]) ≈ Float16(.983)
|
29 |
| - @test gamma_inc(13.5,15.1,0)[2] ≈ 0.305242642543419087 |
30 |
| - @test gamma_inc(11,9,0)[1] ≈ 0.2940116796594881834 |
31 |
| - @test gamma_inc(8,32,0)[1] ≈ 0.99999989060651042057 |
32 |
| - @test gamma_inc(15,16,0)[2] ≈ 0.3675273597655649298 |
33 |
| - @test gamma_inc(15.5,16,0)[2] ≈ 0.4167440299455427811 |
34 |
| - @test gamma_inc(0.9,0.8,0)[1] ≈ 0.59832030278768172 |
35 |
| - @test gamma_inc(1.7,2.5,0)[1] ≈ 0.78446115627678957 |
36 |
| - @test gamma_inc(11.1,0.001,0)[2] ≈ 1.0000 |
37 |
| - @test gamma_inc(1e7, (1e7)+1, 0)[1] ≈ 0.5001682088254367 |
38 |
| - @test gamma_inc(1e7, (1e7)+1, 0)[2] ≈ 0.4998317911745633 |
| 29 | + @test gamma_inc(13.5,15.1)[2] ≈ 0.305242642543419087 |
| 30 | + @test gamma_inc(11,9)[1] ≈ 0.2940116796594881834 |
| 31 | + @test gamma_inc(8,32)[1] ≈ 0.99999989060651042057 |
| 32 | + @test gamma_inc(15,16)[2] ≈ 0.3675273597655649298 |
| 33 | + @test gamma_inc(15.5,16)[2] ≈ 0.4167440299455427811 |
| 34 | + @test gamma_inc(0.9,0.8)[1] ≈ 0.59832030278768172 |
| 35 | + @test gamma_inc(1.7,2.5)[1] ≈ 0.78446115627678957 |
| 36 | + @test gamma_inc(11.1,0.001)[2] ≈ 1.0000 |
| 37 | + @test gamma_inc(1e7, (1e7)+1)[1] ≈ 0.5001682088254367 |
| 38 | + @test gamma_inc(1e7, (1e7)+1)[2] ≈ 0.4998317911745633 |
39 | 39 | @test_throws DomainError gamma_inc(-1,2,2)
|
40 | 40 | @test_throws DomainError gamma_inc(0,0,1)
|
41 | 41 | end
|
|
63 | 63 | @test SpecialFunctions.stirling(x) ≈ log(gamma(x)) - (x-.5)*log(x)+x- log(2*pi)/2.0
|
64 | 64 | end
|
65 | 65 | end
|
| 66 | + |
| 67 | +double(x::Real) = Float64(x) |
| 68 | +double(x::Integer) = Int(x) |
| 69 | +double(x::Complex) = ComplexF64(x) |
| 70 | + |
| 71 | +@testset "upper incomplete gamma function" begin |
| 72 | + setprecision(BigFloat, 256) do |
| 73 | + for a in Any[0:0.4:3; 1:3], x in 0:0.2:2 |
| 74 | + @test gamma(a,x) ≈ gamma(big(a),big(x)) |
| 75 | + end |
| 76 | + @test_throws DomainError gamma(-2.2, -1.3) |
| 77 | + for (a,x, exact) in ( |
| 78 | + (2, big"+1.3", big"0.6268231239782289871813662853957039889809398944861850589869804057956189274569818"), |
| 79 | + (2, big"-1.3", big"-1.100789000285773266137246974803445875429455665367265440176867948378982424804222"), |
| 80 | + (big"2.2", big"1.3", big"0.7550934853735524106456916078787596171599416239996064979513848803118671763945577"), |
| 81 | + (big"-2.2", big"1.3", big"0.03938564959393195337328006806473296774233286427565465045140458665248322893076784"), |
| 82 | + (big"-2.2", big"-1.3"+0im, Complex(big"0.1688350167695890519002747177035271528716667324397453142169971691104641885370081", big"-1.724677939954414412829215929952389349929001266936564849801773346878175589599461")), |
| 83 | + (2, big"1.3"+2im, Complex(big"0.2347744561498965806069446787000456827042253434143074251879541754828136789074293", big"-0.7967951407674886396960561446265346226800340382780520672369163777061700801594228")), |
| 84 | + (big"2.2", big"1.3"+2im, Complex(big"0.4226969694490623767886715572749155659150206342283251276656790859161308520476838", big"-0.9507541450333763666696561254491461255244463810462729822382144498284499948680099")), |
| 85 | + (big"2.2"-2im, big"1.3"+2im, Complex(big"-3.858698824275578861673404086439928163791926530897603434146764316225759116935376", big"0.2105970967650200831829566202893410569725743566037534990454186505024476246014339")), |
| 86 | + (30, big"-1e2", big"-2.080142496354742431762923569133534773079637504483999408076147454085194055640495e+101"), |
| 87 | + ) |
| 88 | + if !(exact isa Complex) # we don't yet have a Complex{BigFloat} gamma function |
| 89 | + @test gamma(a, x) ≈ exact atol=eps(abs(exact))*1000 |
| 90 | + end |
| 91 | + @test gamma(double(a), double(x)) ≈ double(exact) rtol=1e-13 |
| 92 | + end |
| 93 | + end |
| 94 | + @test gamma(30, big(-1000)) ≈ big"-1.914496653187781420578078670260160511219745144309147121829045802464973219500799e+521" rtol=1e-70 |
| 95 | + @test gamma(30, -1000) == -Inf |
| 96 | + @test gamma(Inf, 51.2) == Inf |
| 97 | + @test gamma(-Inf, -51.2) == 0.0 |
| 98 | + @test_throws DomainError gamma(Inf, -51.2) |
| 99 | + @test gamma(2.3, Inf) == 0.0 |
| 100 | + @test gamma(2, -Inf) == -Inf |
| 101 | + @test_throws DomainError gamma(2.2, -Inf) |
| 102 | +end |
0 commit comments