Skip to content

Commit

Permalink
Merge 6d0eb49 into 3f62885
Browse files Browse the repository at this point in the history
  • Loading branch information
tkf committed Jul 12, 2018
2 parents 3f62885 + 6d0eb49 commit 235e6c3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/dual.jl
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,12 @@ for f in (:(Base.:^), :(NaNMath.pow))
begin
v = value(x)
expv = ($f)(v, y)
deriv = y * ($f)(v, y - 1)
return Dual{Tx}(expv, deriv * partials(x))
if y == zero(y)
new_partials = zero(partials(x))
else
new_partials = partials(x) * y * ($f)(v, y - 1)
end
return Dual{Tx}(expv, new_partials)
end,
begin
v = value(y)
Expand Down
10 changes: 10 additions & 0 deletions test/DualTest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -455,4 +455,14 @@ for N in (0,3), M in (0,4), V in (Int, Float32)
end
end

@testset "Exponentiation of zero" begin
x0 = 0.0
x1 = Dual{:t1}(x0, 1.0)
x2 = Dual{:t2}(x1, 1.0)
x3 = Dual{:t3}(x2, 1.0)
@test x3^2 === x3 * x3
@test x2^1 === x2
@test x1^0 === Dual{:t1}(1.0, 0.0)
end

end # module

0 comments on commit 235e6c3

Please sign in to comment.