Skip to content

Commit 6c85048

Browse files
authored
Merge pull request JuliaDiff#36 from thebhatman/patch
Avoid breaking when x is negative
2 parents 0886582 + 5af27fe commit 6c85048

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "DiffRules"
22
uuid = "b552c78f-8df3-52c6-915a-8e097449b14b"
3-
version = "1.1.0"
3+
version = "1.2.0"
44

55
[deps]
66
NaNMath = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3"

src/rules.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ _abs_deriv(x) = signbit(x) ? -one(x) : one(x)
8585
@define_diffrule Base.:*(x, y) = :( $y ), :( $x )
8686
@define_diffrule Base.:/(x, y) = :( one($x) / $y ), :( -($x / $y / $y) )
8787
@define_diffrule Base.:\(x, y) = :( -($y / $x / $x) ), :( one($y) / ($x) )
88-
@define_diffrule Base.:^(x, y) = :( $y * ($x^($y - 1)) ), :( ($x^$y) * log($x) )
88+
@define_diffrule Base.:^(x, y) = :( $y * ($x^($y - 1)) ), :( ($x isa Real && $x<=0) ? Base.oftype(float($x), NaN) : ($x^$y)*log($x) )
8989

9090
if VERSION < v"0.7-"
9191
@define_diffrule Base.atan2(x, y) = :( $y / ($x^2 + $y^2) ), :( -$x / ($x^2 + $y^2) )

0 commit comments

Comments
 (0)