oxiphysics_core/math/
dual_traits.rs1use super::types::Dual;
16
17impl std::ops::Add for Dual {
18 type Output = Self;
19 fn add(self, rhs: Self) -> Self {
20 Self {
21 re: self.re + rhs.re,
22 du: self.du + rhs.du,
23 }
24 }
25}
26
27impl std::ops::Sub for Dual {
28 type Output = Self;
29 fn sub(self, rhs: Self) -> Self {
30 Self {
31 re: self.re - rhs.re,
32 du: self.du - rhs.du,
33 }
34 }
35}
36
37impl std::ops::Mul for Dual {
38 type Output = Self;
39 fn mul(self, rhs: Self) -> Self {
40 Self {
41 re: self.re * rhs.re,
42 du: self.re * rhs.du + self.du * rhs.re,
43 }
44 }
45}
46
47impl std::ops::Div for Dual {
48 type Output = Self;
49 fn div(self, rhs: Self) -> Self {
50 let re = self.re / rhs.re;
51 let du = (self.du * rhs.re - self.re * rhs.du) / (rhs.re * rhs.re);
52 Self { re, du }
53 }
54}
55
56impl std::ops::Neg for Dual {
57 type Output = Self;
58 fn neg(self) -> Self {
59 Self {
60 re: -self.re,
61 du: -self.du,
62 }
63 }
64}