@@ -187,7 +187,7 @@ function En_cf_nogamma(ν::Number, z::Number, n::Int=1000)
187
187
end
188
188
189
189
exppart = exp (- z)
190
- if abs ( real ( exppart)) == Inf && abs ( imag (exppart)) == Inf
190
+ if isinf ( exppart)
191
191
return exp (- z + log (A) - log (B)), iters
192
192
else
193
193
cfpart = A/ B
@@ -235,7 +235,7 @@ function En_cf_gamma(ν::Number, z::Number, n::Int=1000)
235
235
236
236
gammapart = En_safe_gamma_term (ν, z)
237
237
cfpart = exp (- z)
238
- if abs ( real ( cfpart)) == Inf || abs ( imag (cfpart)) == Inf
238
+ if isinf ( cfpart)
239
239
factor = sign (real (cfpart)) + sign (imag (cfpart))* im
240
240
cfpart = exp (- z + log (B) - log (A))
241
241
else
@@ -351,12 +351,11 @@ function En_imagbranchcut(ν::Number, z::Number)
351
351
return imag (impart) * im # get rid of any real error
352
352
end
353
353
354
- const ORIGIN_EXPAND_THRESH = 3
355
354
"""
356
355
expint(z)
357
356
expint(ν, z)
358
357
359
- Computes the exponential integral ``E_ \\ nu(z) = \\ int_0^\\ infty \\ frac{e^{-zt}}{t^\\ nu} dt``.
358
+ Computes the exponential integral ``\\ operatorname{E}_ \\ nu(z) = \\ int_0^\\ infty \\ frac{e^{-zt}}{t^\\ nu} dt``.
360
359
If ``\\ nu`` is not specified, ``\\ nu=1`` is used. Arbitrary complex ``\\ nu`` and ``z`` are supported.
361
360
362
361
External links: [DLMF](https://dlmf.nist.gov/8.19), [Wikipedia](https://en.wikipedia.org/wiki/Exponential_integral)
@@ -384,13 +383,13 @@ function expint(ν::Number, z::Number, niter::Int=1000)
384
383
elseif ν == 1 && real (z) > 0 && z isa Union{Float64, Complex{Float64}}
385
384
return expint_opt (z)
386
385
end
387
- # asymptotic test for |z| → ∞
386
+ # asymptotic test for underflow when Re z → ∞
388
387
# https://functions.wolfram.com/GammaBetaErf/ExpIntegralE/06/02/0003/
389
- if exp ( - z) / z == 0
388
+ if real (z) > - log ( nextfloat ( zero ( real (z)))) + 1 # exp(-z) is zero
390
389
return zero (z)
391
390
end
392
391
393
- if abs (z) < ORIGIN_EXPAND_THRESH
392
+ if abs2 (z) < 9
394
393
# use Taylor series about the origin for small z
395
394
return En_expand_origin (ν, z)
396
395
end
@@ -413,6 +412,7 @@ function expint(ν::Number, z::Number, niter::Int=1000)
413
412
imstart = (imz == 0 ) ? abs (z)* sqrt (eps (typeof (real (z)))) : imz
414
413
z₀ = rez + imstart* im
415
414
E_start, i, _ = En_cf (ν, z₀, quick_niter)
415
+ isnan (E_start) && return E_start
416
416
if imz > 0 && i < nmax
417
417
# didn't need to take any steps
418
418
return doconj ? conj (E_start) : E_start
451
451
expinti(x::Real)
452
452
453
453
Computes the exponential integral function ``\\ operatorname{Ei}(x) = \\ int_{-\\ infty}^x \\ frac{e^t}{t} dt``,
454
- which is equivalent to ``-\\ Re[E_1 (-x)]`` where ``E_1 `` is the `expint` function.
454
+ which is equivalent to ``-\\ Re[\\ operatorname{E}_1 (-x)]`` where ``\\ operatorname{E}_1 `` is the `expint` function.
455
455
"""
456
456
expinti (x:: Real ) = x ≤ 0 ? - expint (- x) : - real (expint (complex (- x)))
457
457
0 commit comments