Skip to content

Commit

Permalink
Handle exp_generic(0.0)
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasnoack committed Aug 16, 2020
1 parent 452ca61 commit 172920f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/exp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,11 @@ by Higham, Nicholas J. in 2005 for algorithm details.
"""
function exp_generic(x, vk=Val{13}())
nx = opnorm(x, 1)
s = ceil(Int, log2(nx))
nxl2 = log2(nx)
if iszero(nx)
return x + oneunit(x)
end
s = ceil(Int, nxl2)
if s >= 1
exp_generic(x/(2^s), vk)^(2^s)
else
Expand Down
5 changes: 5 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ using ForwardDiff
@test ForwardDiff.derivative(exp_generic, 0.1) == exp_generic(0.1)
end

@testset "Issue 42" begin
@test exp_generic(0.0) == 1
@test ForwardDiff.derivative(exp_generic, 0.0) == 1
end

@testset "Phi" begin
# Scalar phi
K = 4
Expand Down

0 comments on commit 172920f

Please sign in to comment.