@@ -317,7 +317,7 @@ Base.AbstractFloat(d::Dual{T,V,N}) where {T,V,N} = convert(Dual{T,promote_type(V
317
317
@inline Base. abs (d:: Dual ) = signbit (value (d)) ? - d : d
318
318
319
319
for (M, f, arity) in DiffRules. diffrules ()
320
- in ((M, f), ((:Base , :^ ), (:NaNMath , :pow ), (:Base , :/ ))) && continue
320
+ in ((M, f), ((:Base , :^ ), (:NaNMath , :pow ), (:Base , :/ ), ( :Base , : + ), ( :Base , : - ) )) && continue
321
321
if arity == 1
322
322
eval (unary_dual_definition (M, f))
323
323
elseif arity == 2
331
331
# Special Cases #
332
332
# ################
333
333
334
+ # +/- #
335
+ # -----#
336
+
337
+ @define_binary_dual_op (
338
+ Base.:+ ,
339
+ begin
340
+ vx, vy = value (x), value (y)
341
+ Dual {Txy} (vx + vy, partials (x) + partials (y))
342
+ end ,
343
+ Dual {Tx} (value (x) + y, partials (x)),
344
+ Dual {Ty} (x + value (y), partials (y))
345
+ )
346
+
347
+ @define_binary_dual_op (
348
+ Base.:- ,
349
+ begin
350
+ vx, vy = value (x), value (y)
351
+ Dual {Txy} (vx - vy, partials (x) - partials (y))
352
+ end ,
353
+ Dual {Tx} (value (x) - y, partials (x)),
354
+ Dual {Ty} (x - value (y), - partials (y))
355
+ )
356
+
357
+ @inline Base.:- (d:: Dual{T} ) where {T} = Dual {T} (- value (d), - partials (d))
358
+
334
359
# * #
335
360
# ---#
336
361
0 commit comments