@@ -393,7 +393,7 @@ Base.float(d::Dual) = convert(float(typeof(d)), d)
393
393
# ##################################
394
394
395
395
for (M, f, arity) in DiffRules. diffrules (filter_modules = nothing )
396
- if (M, f) in ((:Base , :^ ), (:NaNMath , :pow ), (:Base , :/ ), (:Base , :+ ), (:Base , :- ))
396
+ if (M, f) in ((:Base , :^ ), (:NaNMath , :pow ), (:Base , :/ ), (:Base , :+ ), (:Base , :- ), ( :Base , :sin ), ( :Base , :cos ) )
397
397
continue # Skip methods which we define elsewhere.
398
398
elseif ! (isdefined (@__MODULE__ , M) && isdefined (getfield (@__MODULE__ , M), f))
399
399
continue # Skip rules for methods not defined in the current scope
@@ -622,12 +622,19 @@ end
622
622
Dual {Tz} (muladd (x, y, value (z)), partials (z)) # z_body
623
623
)
624
624
625
- # sincos #
625
+ # sin/cos #
626
626
# --------#
627
+ function Base. sin (d:: Dual{T} ) where T
628
+ s, c = sincos (value (d))
629
+ return Dual {T} (s, c * partials (d))
630
+ end
627
631
628
- @inline sincos (x) = (sin (x), cos (x))
632
+ function Base. cos (d:: Dual{T} ) where T
633
+ s, c = sincos (value (d))
634
+ return Dual {T} (c, - s * partials (d))
635
+ end
629
636
630
- @inline function sincos (d:: Dual{T} ) where T
637
+ @inline function Base . sincos (d:: Dual{T} ) where T
631
638
sd, cd = sincos (value (d))
632
639
return (Dual {T} (sd, cd * partials (d)), Dual {T} (cd, - sd * partials (d)))
633
640
end
0 commit comments