From 8450f0f8287f5895e0e58e89c789338ae88a1690 Mon Sep 17 00:00:00 2001 From: Andreas Noack Date: Thu, 24 Nov 2022 22:41:00 +0100 Subject: [PATCH] Add a expm1 method for Float16 for older Julia versions --- src/distrs/tdist.jl | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/distrs/tdist.jl b/src/distrs/tdist.jl index 0a56760..0ba04f0 100644 --- a/src/distrs/tdist.jl +++ b/src/distrs/tdist.jl @@ -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))...)