File tree Expand file tree Collapse file tree 2 files changed +18
-3
lines changed Expand file tree Collapse file tree 2 files changed +18
-3
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ fn main() {
16
16
ac. emit_expression_cfg ( "1f64.copysign(-1f64)" , "has_copysign" ) ;
17
17
}
18
18
ac. emit_expression_cfg ( "1f64.is_subnormal()" , "has_is_subnormal" ) ;
19
+ ac. emit_expression_cfg ( "1f64.total_cmp(&2f64)" , "has_total_cmp" ) ;
19
20
20
21
ac. emit_expression_cfg ( "1u32.to_ne_bytes()" , "has_int_to_from_bytes" ) ;
21
22
ac. emit_expression_cfg ( "3.14f64.to_ne_bytes()" , "has_float_to_from_bytes" ) ;
Original file line number Diff line number Diff line change @@ -2268,17 +2268,31 @@ pub trait TotalOrder {
2268
2268
fn total_cmp ( & self , other : & Self ) -> Ordering ;
2269
2269
}
2270
2270
macro_rules! totalorder_impl {
2271
- ( $T: ident) => {
2271
+ ( $T: ident, $I : ident , $U : ident , $bits : expr ) => {
2272
2272
impl TotalOrder for $T {
2273
2273
#[ inline]
2274
+ #[ cfg( has_total_cmp) ]
2274
2275
fn total_cmp( & self , other: & Self ) -> Ordering {
2276
+ // Forward to the core implementation
2275
2277
Self :: total_cmp( & self , other)
2276
2278
}
2279
+ #[ inline]
2280
+ #[ cfg( not( has_total_cmp) ) ]
2281
+ fn total_cmp( & self , other: & Self ) -> Ordering {
2282
+ // Backport the core implementation (since 1.62)
2283
+ let mut left = self . to_bits( ) as $I;
2284
+ let mut right = other. to_bits( ) as $I;
2285
+
2286
+ left ^= ( ( ( left >> ( $bits - 1 ) ) as $U) >> 1 ) as $I;
2287
+ right ^= ( ( ( right >> ( $bits - 1 ) ) as $U) >> 1 ) as $I;
2288
+
2289
+ left. cmp( & right)
2290
+ }
2277
2291
}
2278
2292
} ;
2279
2293
}
2280
- totalorder_impl ! ( f64 ) ;
2281
- totalorder_impl ! ( f32 ) ;
2294
+ totalorder_impl ! ( f64 , i64 , u64 , 64 ) ;
2295
+ totalorder_impl ! ( f32 , i32 , u32 , 32 ) ;
2282
2296
2283
2297
#[ cfg( test) ]
2284
2298
mod tests {
You can’t perform that action at this time.
0 commit comments