Skip to content

Commit f35f1c7

Browse files
Merge pull request #195 from araujoms/incgamma
add logabsgamma and unrelated fixes
2 parents ebb46da + 91c5278 commit f35f1c7

File tree

7 files changed

+42
-25
lines changed

7 files changed

+42
-25
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
1818

1919
[compat]
2020
Polynomials = "1, 2, 3, 4, 5, 6"
21-
Quadmath = "0.4, 0.5, 0.6, 0.7, 0.8"
21+
Quadmath = "0.5.10, 0.6, 0.7, 0.8"
2222
Requires = "1"
2323
SpecialFunctions = "1.0, 1.1, 2.0, 2.1, 2.2, 2.3, 2.4, 2.5"
2424
GenericLinearAlgebra = "0.2.5, 0.3, 0.4, 0.5, 0.6"

src/math/ops/op_dd_dd.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ end
5757

5858
function sqrt_dd_dd(x::Tuple{T,T}) where {T<:IEEEFloat}
5959
iszero(HI(x)) && return x
60-
signbit(HI(x)) && throw(DomainError("sqrt(x) expects x >= 0"))
60+
signbit(HI(x)) && throw(DomainError("sqrt(x) expects x >= 0"))
6161

6262
ahi, alo = HILO(x)
6363
s = sqrt(ahi)

src/math/special/gamma_erf.jl

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
erf(x::Double64) = Double64Float128(erf, x)
22
erfc(x::Double64) = Double64Float128(erfc, x)
33
gamma(x::Double64) = Double64Float128(gamma, x)
4-
lgamma(x::Double64) = Double64Float128(lgamma, x)
5-
loggamma(x::Double64) = Double64Float128(lgamma, x)
64

75
erf(x::Double32) = Double32Float128(erf, x)
86
erfc(x::Double32) = Double32Float128(erfc, x)
97
gamma(x::Double32) = Double32Float128(gamma, x)
10-
lgamma(x::Double32) = Double32Float128(lgamma, x)
11-
loggamma(x::Double32) = Double32Float128(lgamma, x)
128

139
erf(x::Double16) = Double16Float128(erf, x)
1410
erfc(x::Double16) = Double16Float128(erfc, x)
1511
gamma(x::Double16) = Double16Float128(gamma, x)
16-
lgamma(x::Double16) = Double16Float128(lgamma, x)
17-
loggamma(x::Double16) = Double16Float128(lgamma, x)
12+
13+
function logabsgamma(x::DoubleFloat{T}) where {T<:IEEEFloat}
14+
result = logabsgamma(Float128(x))
15+
return DoubleFloat{T}(result[1]), result[2]
16+
end

src/math/special/specialfunctions.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import .SpecialFunctions
2-
import .SpecialFunctions: erf, erfc, gamma, lgamma,
3-
besselj0, besselj1, besselj, bessely0, bessely1, bessely
2+
import .SpecialFunctions: erf, erfc, gamma, logabsgamma,
3+
besselj0, besselj1, besselj, bessely0, bessely1, bessely,
4+
ellipk
45

56
include("agm.jl")
67
include("bessel.jl")

test/fma.jl

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
@testset "fma" begin
22

3-
@test HILO(fma(Float64(pi), Float64(phi), Double64(gamma))) == (5.660419357216792, 4.1344240638440936e-16)
4-
@test HILO(fma(Float64(pi), Double64(phi), Float64(gamma))) == (5.660419357216792, 2.477303893634162e-16)
5-
@test HILO(fma(Double64(pi), Float64(phi), Float64(gamma))) == (5.660419357216793, -2.7164108363986695e-16)
6-
@test HILO(fma(Double64(pi), Double64(phi), Float64(gamma))) == (5.660419357216793, -4.422960158132908e-16)
7-
@test HILO(fma(Double64(pi), Float64(phi), Double64(gamma))) == (5.660419357216793, -2.765839987922976e-16)
8-
@test HILO(fma(Double64(pi), Double64(phi), Double64(gamma))) == (5.660419357216792, 4.4093948873440384e-16)
3+
@test HILO(fma(Float64(pi), Float64(phi), Double64(eulergamma))) == (5.660419357216792, 4.1344240638440936e-16)
4+
@test HILO(fma(Float64(pi), Double64(phi), Float64(eulergamma))) == (5.660419357216792, 2.477303893634162e-16)
5+
@test HILO(fma(Double64(pi), Float64(phi), Float64(eulergamma))) == (5.660419357216793, -2.7164108363986695e-16)
6+
@test HILO(fma(Double64(pi), Double64(phi), Float64(eulergamma))) == (5.660419357216793, -4.422960158132908e-16)
7+
@test HILO(fma(Double64(pi), Float64(phi), Double64(eulergamma))) == (5.660419357216793, -2.765839987922976e-16)
8+
@test HILO(fma(Double64(pi), Double64(phi), Double64(eulergamma))) == (5.660419357216792, 4.4093948873440384e-16)
99

10-
@test HILO(muladd(Float64(pi), Float64(phi), Double64(gamma))) == (5.660419357216792, 4.1344240638440936e-16)
11-
@test HILO(muladd(Float64(pi), Double64(phi), Float64(gamma))) == (5.660419357216792, 2.477303893634162e-16)
12-
@test HILO(muladd(Double64(pi), Float64(phi), Float64(gamma))) == (5.660419357216793, -2.7164108363986695e-16)
13-
@test HILO(muladd(Double64(pi), Double64(phi), Float64(gamma))) == (5.660419357216793, -4.422960158132908e-16)
14-
@test HILO(muladd(Double64(pi), Float64(phi), Double64(gamma))) == (5.660419357216793, -2.765839987922976e-16)
15-
@test HILO(muladd(Double64(pi), Double64(phi), Double64(gamma))) == (5.660419357216792, 4.4093948873440384e-16)
10+
@test HILO(muladd(Float64(pi), Float64(phi), Double64(eulergamma))) == (5.660419357216792, 4.1344240638440936e-16)
11+
@test HILO(muladd(Float64(pi), Double64(phi), Float64(eulergamma))) == (5.660419357216792, 2.477303893634162e-16)
12+
@test HILO(muladd(Double64(pi), Float64(phi), Float64(eulergamma))) == (5.660419357216793, -2.7164108363986695e-16)
13+
@test HILO(muladd(Double64(pi), Double64(phi), Float64(eulergamma))) == (5.660419357216793, -4.422960158132908e-16)
14+
@test HILO(muladd(Double64(pi), Float64(phi), Double64(eulergamma))) == (5.660419357216793, -2.765839987922976e-16)
15+
@test HILO(muladd(Double64(pi), Double64(phi), Double64(eulergamma))) == (5.660419357216792, 4.4093948873440384e-16)
1616

1717
end

test/runtests.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ using Printf
99
using Random
1010

1111
const phi = Base.MathConstants.golden
12-
const gamma = Base.MathConstants.eulergamma
12+
const eulergamma = Base.MathConstants.eulergamma
1313

1414
const phi_df64 = Double64(phi)
1515
const phi_df32 = Double32(phi)
16-
const gamma_df64 = Double64(gamma)
17-
const gamma_df32 = Double32(gamma)
16+
const gamma_df64 = Double64(eulergamma)
17+
const gamma_df32 = Double32(eulergamma)
1818

1919
const phi_df64hi = HI(phi_df64); const phi_df64lo = LO(phi_df64)
2020
const phi_df32hi = HI(phi_df32); const phi_df32lo = LO(phi_df32)

test/special_functions.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,18 @@
1+
using SpecialFunctions
12

3+
@testset "special functions" begin
4+
# The intention here is not to check the accuracy of the libraries,
5+
# rather the sanity of library calls:
6+
piq = Double64(pi)
7+
halfq = Double64(0.5)
8+
@test gamma(halfq) sqrt(piq)
9+
for func in (erf, erfc, besselj0, besselj1, bessely0, bessely1, loggamma)
10+
@test func(halfq) func(0.5)
11+
end
12+
for func in (bessely, besselj)
13+
@test func(3,halfq) func(3,0.5)
14+
end
15+
@test gamma(Double64(2),3) gamma(2,3)
16+
@test all(logabsgamma(Double64(-0.5)) .≈ logabsgamma(-0.5))
17+
@test all(logabsgamma(Double64(-1.5)) .≈ logabsgamma(-1.5))
18+
end

0 commit comments

Comments
 (0)