|
44 | 44 | //! [`UtcParams`] object to handle the leap second conversion and one which doesn't
|
45 | 45 | //! take a [`UtcParams`] object but has `_hardcoded` appended to the function name.
|
46 | 46 |
|
47 |
| -use std::cmp::Ordering; |
48 | 47 | use std::error::Error;
|
49 | 48 | use std::fmt;
|
50 | 49 | use std::ops::{Add, AddAssign, Sub, SubAssign};
|
@@ -301,20 +300,16 @@ impl GpsTime {
|
301 | 300 | GloTime(unsafe { swiftnav_sys::gps2glo(self.c_ptr(), std::ptr::null()) })
|
302 | 301 | }
|
303 | 302 |
|
| 303 | + #[rustversion::since(1.62)] |
304 | 304 | /// Compare between itself and other GpsTime
|
305 |
| - /// Checks whether week number is same which then mirrors [`https://github.com/rust-lang/rust/blob/481db40311cdd241ae4d33f34f2f75732e44d8e8/library/core/src/num/f64.rs#L1228`](f64::total_cmp()) |
306 |
| - pub fn total_cmp(&self, other: &GpsTime) -> Ordering { |
| 305 | + /// Checks whether week number is same which then mirrors |
| 306 | + /// [f64::total_cmp()](https://doc.rust-lang.org/std/primitive.f64.html#method.total_cmp) |
| 307 | + pub fn total_cmp(&self, other: &GpsTime) -> std::cmp::Ordering { |
307 | 308 | if self.wn() != other.wn() {
|
308 | 309 | self.wn().cmp(&other.wn())
|
309 | 310 | } else {
|
310 |
| - //TODO: replace with f64::total_cmp |
311 |
| - let mut left = self.tow().to_bits() as i64; |
312 |
| - let mut right = other.tow().to_bits() as i64; |
313 |
| - |
314 |
| - left ^= (((left >> 63) as u64) >> 1) as i64; |
315 |
| - right ^= (((right >> 63) as u64) >> 1) as i64; |
316 |
| - |
317 |
| - left.cmp(&right) |
| 311 | + let other = other.tow(); |
| 312 | + self.tow().total_cmp(&other) |
318 | 313 | }
|
319 | 314 | }
|
320 | 315 | }
|
@@ -922,6 +917,26 @@ mod tests {
|
922 | 917 | assert!(t3 >= t3);
|
923 | 918 | }
|
924 | 919 |
|
| 920 | + #[rustversion::since(1.62)] |
| 921 | + #[test] |
| 922 | + fn total_order() { |
| 923 | + use std::cmp::Ordering; |
| 924 | + |
| 925 | + let t1 = GpsTime::new(10, 234.566).unwrap(); |
| 926 | + let t2 = GpsTime::new(10, 234.567).unwrap(); |
| 927 | + let t3 = GpsTime::new(10, 234.568).unwrap(); |
| 928 | + |
| 929 | + assert!(t1.total_cmp(&t2) == Ordering::Less); |
| 930 | + assert!(t2.total_cmp(&t3) == Ordering::Less); |
| 931 | + assert!(t1.total_cmp(&t3) == Ordering::Less); |
| 932 | + |
| 933 | + assert!(t2.total_cmp(&t1) == Ordering::Greater); |
| 934 | + assert!(t3.total_cmp(&t2) == Ordering::Greater); |
| 935 | + assert!(t3.total_cmp(&t1) == Ordering::Greater); |
| 936 | + |
| 937 | + assert!(t1.total_cmp(&t1) == Ordering::Equal); |
| 938 | + } |
| 939 | + |
925 | 940 | #[test]
|
926 | 941 | fn add_duration() {
|
927 | 942 | let mut t = GpsTime::new(0, 0.0).unwrap();
|
|
0 commit comments