Skip to content

Commit f99d068

Browse files
authored
use mpfr_eint for expint/expinti of BigFloat (#258)
* use mpfr_eint for expint/expinti of BigFloat * another test * setprecision before BigFloat test
1 parent a6edb57 commit f99d068

File tree

2 files changed

+44
-15
lines changed

2 files changed

+44
-15
lines changed

src/expint.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,18 @@ function expint(z::Complex{Float64})
132132
end
133133
expint(x::Float64) = expint_opt(x)
134134

135+
function expint(x::BigFloat)
136+
iszero(x) && return Inf
137+
signbit(x) && throw(DomainError(x, "negative argument, convert to complex first"))
138+
return -expinti(-x)
139+
end
140+
135141
expint(z::Union{T,Complex{T},Rational{T},Complex{Rational{T}}}) where {T<:Integer} = expint(float(z))
136142
expint(x::Number) = expint(1, x)
137143
expint(z::Float32) = Float32(expint(Float64(z)))
138144
expint(z::ComplexF32) = ComplexF32(expint(ComplexF64(z)))
145+
expint(z::Float16) = Float16(expint(Float64(z)))
146+
expint(z::ComplexF16) = ComplexF16(expint(ComplexF64(z)))
139147

140148
# Continued fraction for En(ν, z) that doesn't use a term with
141149
# the gamma function: https://functions.wolfram.com/GammaBetaErf/ExpIntegralE/10/0001/
@@ -496,3 +504,10 @@ end
496504

497505
expinti(z::Union{T,Rational{T}}) where {T<:Integer} = expinti(float(z))
498506
expinti(z::Float32) = Float32(expinti(Float64(z)))
507+
expinti(z::Float16) = Float16(expinti(Float64(z)))
508+
509+
function expinti(x::BigFloat)
510+
z = BigFloat()
511+
ccall((:mpfr_eint, :libmpfr), Int32, (Ref{BigFloat}, Ref{BigFloat}, Base.MPFR.MPFRRoundingMode), z, x, Base.MPFR.ROUNDING_MODE[])
512+
return z
513+
end

0 commit comments

Comments
 (0)