1use crate::{Dt, Real};
2use core::cmp::Ordering;
3use core::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign};
4
5impl Add<Dt> for Dt {
6 type Output = Self;
7
8 #[inline]
9 fn add(self, rhs: Dt) -> Self {
10 self.add(rhs)
11 }
12}
13
14impl AddAssign<Dt> for Dt {
15 #[inline]
16 fn add_assign(&mut self, rhs: Dt) {
17 *self = self.add(rhs);
18 }
19}
20
21impl Sub<Dt> for Dt {
22 type Output = Self;
23
24 #[inline]
25 fn sub(self, rhs: Dt) -> Self {
26 self.sub(rhs)
27 }
28}
29
30impl SubAssign<Dt> for Dt {
31 #[inline]
32 fn sub_assign(&mut self, rhs: Dt) {
33 *self = self.sub(rhs);
34 }
35}
36
37impl Neg for Dt {
38 type Output = Self;
39
40 #[inline]
42 fn neg(self) -> Self {
43 self.neg()
44 }
45}
46
47impl Mul<i64> for Dt {
48 type Output = Self;
49
50 #[inline]
52 fn mul(self, rhs: i64) -> Self {
53 self.mul(rhs)
54 }
55}
56
57impl MulAssign<i64> for Dt {
58 #[inline]
60 fn mul_assign(&mut self, rhs: i64) {
61 *self = self.mul(rhs);
62 }
63}
64
65impl Div<i64> for Dt {
66 type Output = Self;
67
68 #[inline]
70 fn div(self, rhs: i64) -> Self {
71 self.div(rhs)
72 }
73}
74
75impl DivAssign<i64> for Dt {
76 #[inline]
78 fn div_assign(&mut self, rhs: i64) {
79 *self = self.div(rhs);
80 }
81}
82
83impl Mul<f64> for Dt {
84 type Output = Self;
85
86 #[inline]
87 fn mul(self, rhs: f64) -> Self {
88 self.mul_by_f(rhs)
89 }
90}
91
92impl MulAssign<f64> for Dt {
93 #[inline]
94 fn mul_assign(&mut self, rhs: f64) {
95 *self = self.mul_by_f(rhs);
96 }
97}
98
99impl Div<f64> for Dt {
100 type Output = Self;
101
102 #[inline]
103 fn div(self, rhs: f64) -> Self {
104 self.div_by_f(rhs)
105 }
106}
107
108impl DivAssign<f64> for Dt {
109 #[inline]
110 fn div_assign(&mut self, rhs: f64) {
111 *self = self.div_by_f(rhs);
112 }
113}
114
115impl Mul<Dt> for i64 {
116 type Output = Dt;
117
118 #[inline]
119 fn mul(self, rhs: Dt) -> Dt {
120 rhs.mul(self)
121 }
122}
123
124impl Mul<Dt> for f64 {
125 type Output = Dt;
126
127 #[inline]
128 fn mul(self, rhs: Dt) -> Dt {
129 rhs.mul_by_f(self)
130 }
131}
132
133impl Div<Dt> for Dt {
134 type Output = Real;
135
136 #[inline]
137 fn div(self, rhs: Dt) -> Real {
138 self.div_dt(rhs)
139 }
140}
141
142impl Dt {
143 pub const fn cmp(&self, other: &Self) -> Ordering {
150 let a = self.carry_attos();
151 let b = other.carry_attos();
152
153 if a.sec < b.sec {
154 Ordering::Less
155 } else if a.sec > b.sec {
156 Ordering::Greater
157 } else if a.attos < b.attos {
158 Ordering::Less
159 } else if a.attos > b.attos {
160 Ordering::Greater
161 } else {
162 Ordering::Equal
163 }
164 }
165
166 #[inline]
171 pub const fn min(self, other: Self) -> Self {
172 match self.cmp(&other) {
173 Ordering::Greater => other,
174 _ => self,
175 }
176 }
177
178 #[inline]
183 pub const fn max(self, other: Self) -> Self {
184 match self.cmp(&other) {
185 Ordering::Less => other,
186 _ => self,
187 }
188 }
189
190 #[inline]
194 pub const fn eq(&self, other: &Self) -> bool {
195 matches!(Dt::cmp(self, other), Ordering::Equal)
196 }
197
198 pub const fn lt(&self, other: &Self) -> bool {
202 matches!(self.cmp(other), Ordering::Less)
203 }
204
205 pub const fn gt(&self, other: &Self) -> bool {
209 matches!(self.cmp(other), Ordering::Greater)
210 }
211
212 pub const fn le(&self, other: &Self) -> bool {
216 !matches!(self.cmp(other), Ordering::Greater)
217 }
218
219 pub const fn ge(&self, other: &Self) -> bool {
223 !matches!(self.cmp(other), Ordering::Less)
224 }
225}
226
227impl PartialEq for Dt {
228 #[inline]
229 fn eq(&self, other: &Self) -> bool {
230 Dt::eq(self, other)
231 }
232}
233
234impl Eq for Dt {}
235
236impl PartialOrd for Dt {
237 #[inline]
238 fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
239 Some(Dt::cmp(self, other))
240 }
241}
242
243impl Ord for Dt {
244 #[inline]
245 fn cmp(&self, other: &Self) -> Ordering {
246 Dt::cmp(self, other)
247 }
248}
249
250impl core::hash::Hash for Dt {
251 fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
255 self.sec.hash(state);
256 self.attos.hash(state);
257 }
258}