From db5c8ff0ab824ba4b8bcd6cdb0b349a8e10399f4 Mon Sep 17 00:00:00 2001 From: Moelf Date: Thu, 9 May 2019 10:57:02 -0700 Subject: [PATCH] add mod2pi and its test --- src/rules.jl | 1 + test/runtests.jl | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/src/rules.jl b/src/rules.jl index 5ed0ca8..e2c9c19 100644 --- a/src/rules.jl +++ b/src/rules.jl @@ -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) ) diff --git a/test/runtests.jl b/test/runtests.jl index 51455db..ede8617 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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 "mod2pi" == string($M.$f) + goo = 4pi + $modifier + @test NaN === $deriv + end end elseif arity == 2 @test DiffRules.hasdiffrule(M, f, 2)