Skip to content

Commit 92e773f

Browse files
committed
lambertw(): use inve constant
1 parent 17729d4 commit 92e773f

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/SpecialFunctions.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ using IrrationalConstants:
1111
invsqrt2π,
1212
logtwo,
1313
logπ,
14-
log2π
14+
log2π,
15+
inve
1516

1617
import ChainRulesCore
1718
import LogExpFunctions

src/lambertw.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ _lambertw(x::Real, k::Integer, maxits::Integer) = _lambertw(x, Val(Int(k)), maxi
5252
function _lambertw(x::T, ::Val{0}, maxits::Integer) where T<:Real
5353
isfinite(x) || return x
5454
one_t = one(T)
55-
oneoe = -inv(convert(T, MathConstants.e)) # The branch point
55+
oneoe = -T(inve) # The branch point
5656
x == oneoe && return -one_t
5757
oneoe < x || throw(DomainError(x))
5858
itwo_t = 1 / convert(T, 2)
@@ -68,7 +68,7 @@ end
6868

6969
# Real x, k = -1
7070
function _lambertw(x::T, ::Val{-1}, maxits::Integer) where T<:Real
71-
oneoe = -inv(convert(T, MathConstants.e))
71+
oneoe = -T(inve)
7272
x == oneoe && return -one(T) # W approaches -1 as x -> -1/e from above
7373
oneoe < x || throw(DomainError(x)) # branch domain exludes x < -1/e
7474
x == zero(T) && return -convert(T, Inf) # W decreases w/o bound as x -> 0 from below
@@ -86,7 +86,7 @@ _lambertw(z::Complex{<:Integer}, k::Integer, maxits::Integer) = _lambertw(float(
8686
function _lambertw(z::Complex{T}, k::Integer, maxits::Integer) where T<:Real
8787
local w::Complex{T}
8888
pointseven = 7//10
89-
if abs(z) <= inv(convert(T, MathConstants.e))
89+
if abs(z) <= T(inve)
9090
if z == 0
9191
k == 0 && return z
9292
return complex(-convert(T, Inf), zero(T))
@@ -238,7 +238,7 @@ function lambertwbp_series_length(x::Real)
238238
x < 5e-2 && return 32
239239
x < 1e-1 && return 50
240240
x < 1.9e-1 && return 100
241-
x > inv(MathConstants.e) && throw(DomainError(x)) # radius of convergence
241+
x > typeof(x)(inve) && throw(DomainError(x)) # radius of convergence
242242
return 290 # good for x approx .32
243243
end
244244

0 commit comments

Comments
 (0)