Skip to content

Commit

Permalink
Dual raised to power UInt64(0) gives NaN dualpart (#82)
Browse files Browse the repository at this point in the history
* test and fix for nan epsilon of dual^UInt64(0)

* "0.6.3" -> "0.6.4"
  • Loading branch information
jwscook committed Mar 18, 2021
1 parent 6127786 commit 23cbf38
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "DualNumbers"
uuid = "fa6b7ba4-c1ee-5f82-b5fc-ecf0adba8f74"
version = "0.6.3"
version = "0.6.4"

[deps]
Calculus = "49dc2e85-a5d0-5ad3-a950-438e2897f1b9"
Expand Down
1 change: 1 addition & 0 deletions src/dual.jl
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ end
Base.mod(z::Dual, n::Number) = Dual(mod(value(z), n), epsilon(z))

# these two definitions are needed to fix ambiguity warnings
Base.:^(z::Dual, n::Unsigned) = z^Signed(n)
Base.:^(z::Dual, n::Integer) = Dual(value(z)^n, epsilon(z)*n*value(z)^(n-1))
Base.:^(z::Dual, n::Rational) = Dual(value(z)^n, epsilon(z)*n*value(z)^(n-1))

Expand Down
3 changes: 3 additions & 0 deletions test/automatic_differentiation_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ y = x^3.0
@test value(y) 2.0^3
@test epsilon(y) 3.0*2^2

y = Dual(2.0, 1)^UInt64(0)
@test !isnan(epsilon(y))

y = sin(x)+exp(x)
@test value(y) sin(2)+exp(2)
@test epsilon(y) cos(2)+exp(2)
Expand Down

2 comments on commit 23cbf38

@dlfivefifty
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/32256

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.6.4 -m "<description of version>" 23cbf38bf2dab60a877bba378f037f71c917ce06
git push origin v0.6.4

Please sign in to comment.