Skip to content

Commit 94e1f45

Browse files
araujomsRalphASdevmotion
authored
add logabsgamma (#72)
* add logabsgamma * Update src/specfun.jl Co-authored-by: RalphAS <[email protected]> * handle Inf and NaN Co-authored-by: David Widmann <[email protected]> * match sign also for negative integers * remove deprecated lgamma (SpecialFunctions will take care of it) --------- Co-authored-by: RalphAS <[email protected]> Co-authored-by: David Widmann <[email protected]>
1 parent 26569b9 commit 94e1f45

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/specfun.jl

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import .SpecialFunctions
22
import .SpecialFunctions: erf, erfc, besselj0, besselj1, bessely0, bessely1,
3-
besselj, bessely, gamma, lgamma
3+
besselj, bessely, gamma, logabsgamma
44

55
erf(x::Float128) =
66
Float128(@ccall(libquadmath.erfq(x::Cfloat128)::Cfloat128))
@@ -24,5 +24,9 @@ bessely(n::Integer, x::Float128) =
2424

2525
gamma(x::Float128) =
2626
Float128(@ccall(libquadmath.tgammaq(x::Cfloat128)::Cfloat128))
27-
lgamma(x::Float128) =
28-
Float128(@ccall(libquadmath.lgammaq(x::Cfloat128)::Cfloat128))
27+
28+
function logabsgamma(x::Float128)
29+
result = Float128(@ccall(libquadmath.lgammaq(x::Cfloat128)::Cfloat128))
30+
sign = !isfinite(result) || x >= 0 || !iszero(mod(ceil(x), 2)) ? 1 : -1
31+
return result, sign
32+
end

test/specfun.jl

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@ using SpecialFunctions
66
piq = Float128(pi)
77
halfq = Float128(0.5)
88
@test gamma(halfq) sqrt(piq)
9-
for func in (erf, erfc, besselj0, besselj1, bessely0, bessely1, lgamma)
9+
for func in (erf, erfc, besselj0, besselj1, bessely0, bessely1, loggamma)
1010
@test func(halfq) func(0.5)
1111
end
1212
for func in (bessely, besselj)
1313
@test func(3,halfq) func(3,0.5)
1414
end
15+
@test gamma(Float128(2),3) gamma(2,3)
16+
@test all(logabsgamma(Float128(-0.5)) .≈ logabsgamma(-0.5))
17+
@test all(logabsgamma(Float128(-1.5)) .≈ logabsgamma(-1.5))
1518
end

0 commit comments

Comments
 (0)