Skip to content

Commit 27b44d6

Browse files
fix xexpy(0, 1000) (#80)
* fix `xexpy(0, 1000)` * add xexpy tests * fixup * update doc * Update src/basicfuns.jl Co-authored-by: David Widmann <[email protected]> --------- Co-authored-by: David Widmann <[email protected]>
1 parent 8b28b3a commit 27b44d6

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/basicfuns.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ end
6262
"""
6363
$(SIGNATURES)
6464
65-
Return `x * exp(y)` for `y > -Inf`, or zero if `y == -Inf`.
65+
Return `x * exp(y)` for `y > -Inf`, or zero if `y == -Inf` or if `x == 0` and `y` is finite.
6666
6767
```jldoctest
6868
julia> xexpy(1.0, -Inf)
@@ -72,7 +72,7 @@ julia> xexpy(1.0, -Inf)
7272
function xexpy(x::Real, y::Real)
7373
expy = exp(y)
7474
result = x * expy
75-
return iszero(expy) && !isnan(x) ? zero(result) : result
75+
return (iszero(x) && isfinite(y)) || (iszero(expy) && !isnan(x)) ? zero(result) : result
7676
end
7777

7878
# The following bounds are precomputed versions of the following abstract

test/basicfuns.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ end
7373
for x in (randn(), randn(Float32))
7474
@test xexpy(x, x) xexpx(x)
7575
end
76+
@test xexpy(0, 1000) == 0.0
77+
@test isnan(xexpy(0, Inf))
78+
@test isnan(xexpy(0, NaN))
7679
end
7780

7881
@testset "logistic & logit" begin

0 commit comments

Comments
 (0)