Skip to content

Commit

Permalink
Add a expm1 method for Float16 for older Julia versions
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasnoack committed Nov 24, 2022
1 parent 09e2695 commit 8450f0f
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/distrs/tdist.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,24 @@ tdistinvcdf(ν::Real, p::Real) = tdistinvcdf(map(float, promote(ν, p))...)

tdistinvccdf::Real, p::Real) = -tdistinvcdf(ν, p)

if VERSION < v"1.7.0-beta1"
function _expm1(x::Float16)
if -0.2 < x < 0.1
return @evalpoly(x, Float16(0), Float16(1), Float16(1/2), Float16(1/6), Float16(1/24), Float16(1/120))
else
return exp(x) - 1
end
end
end
_expm1(x::Number) = expm1(x)

function tdistinvlogcdf::T, logp::T) where T<:Real
if isinf(ν)
return norminvlogcdf(logp)
elseif logp < -log(2)
return -sqrt(fdistinvlogccdf(one(ν), ν, logp + log(2*one(logp))))
else
sqrt(fdistinvccdf(one(ν), ν, -2*expm1(logp)))
sqrt(fdistinvccdf(one(ν), ν, -2*_expm1(logp)))
end
end
tdistinvlogcdf::Real, logp::Real) = tdistinvlogcdf(map(float, promote(ν, logp))...)
Expand Down

0 comments on commit 8450f0f

Please sign in to comment.