Skip to content

Commit

Permalink
add mod2pi and its test
Browse files Browse the repository at this point in the history
  • Loading branch information
Moelf committed May 9, 2019
1 parent a9b00c8 commit 8b6b48e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/rules.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
@define_diffrule Base.acsch(x) = :( -inv(abs($x) * sqrt(1 + $x^2)) )
@define_diffrule Base.acoth(x) = :( inv(1 - $x^2) )
@define_diffrule Base.deg2rad(x) = :( π / 180 )
@define_diffrule Base.mod2pi(x) = :( isinteger($x / 2pi) ? NaN : 1 )
@define_diffrule Base.rad2deg(x) = :( 180 / π )
if VERSION < v"0.7-"
@define_diffrule Base.gamma(x) = :( digamma($x) * gamma($x) )
Expand Down
5 changes: 5 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ for (M, f, arity) in DiffRules.diffrules()
@eval begin
goo = rand() + $modifier
@test isapprox($deriv, finitediff($M.$f, goo), rtol=0.05)
# test for 2pi functions
if occursin("mod2pi", string($M.$f))
goo = 4pi + $modifier
@test NaN === $deriv
end
end
elseif arity == 2
@test DiffRules.hasdiffrule(M, f, 2)
Expand Down

0 comments on commit 8b6b48e

Please sign in to comment.