Skip to content

Commit 621b1b7

Browse files
committed
Use Ordering from core where appropriate
1 parent 2a76a8d commit 621b1b7

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/float.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use core::cmp::Ordering;
12
use core::num::FpCategory;
23
use core::ops::{Add, Div, Neg};
34

@@ -2246,30 +2247,31 @@ pub trait TotalOrder {
22462247
/// # Examples
22472248
/// ```
22482249
/// use num_traits::float::TotalOrder;
2250+
/// use std::cmp::Ordering;
22492251
/// use std::{f32, f64};
22502252
///
22512253
/// fn check_eq<T: TotalOrder>(x: T, y: T) {
2252-
/// assert_eq!(x.total_cmp(&y), std::cmp::Ordering::Equal);
2254+
/// assert_eq!(x.total_cmp(&y), Ordering::Equal);
22532255
/// }
22542256
///
22552257
/// check_eq(f64::NAN, f64::NAN);
22562258
/// check_eq(f32::NAN, f32::NAN);
22572259
///
22582260
/// fn check_lt<T: TotalOrder>(x: T, y: T) {
2259-
/// assert_eq!(x.total_cmp(&y), std::cmp::Ordering::Less);
2261+
/// assert_eq!(x.total_cmp(&y), Ordering::Less);
22602262
/// }
22612263
///
22622264
/// check_lt(-f64::NAN, f64::NAN);
22632265
/// check_lt(f64::INFINITY, f64::NAN);
22642266
/// check_lt(-0.0_f64, 0.0_f64);
22652267
/// ```
2266-
fn total_cmp(&self, other: &Self) -> std::cmp::Ordering;
2268+
fn total_cmp(&self, other: &Self) -> Ordering;
22672269
}
22682270
macro_rules! totalorder_impl {
22692271
($T:ident) => {
22702272
impl TotalOrder for $T {
22712273
#[inline]
2272-
fn total_cmp(&self, other: &Self) -> std::cmp::Ordering {
2274+
fn total_cmp(&self, other: &Self) -> Ordering {
22732275
Self::total_cmp(&self, other)
22742276
}
22752277
}
@@ -2413,14 +2415,17 @@ mod tests {
24132415
#[test]
24142416
fn total_cmp() {
24152417
use crate::float::{Float, TotalOrder};
2418+
use core::cmp::Ordering;
2419+
use core::{f32, f64};
2420+
24162421
fn check_eq<T: Float + TotalOrder>(x: T, y: T) {
2417-
assert_eq!(x.total_cmp(&y), std::cmp::Ordering::Equal);
2422+
assert_eq!(x.total_cmp(&y), Ordering::Equal);
24182423
}
24192424
fn check_lt<T: Float + TotalOrder>(x: T, y: T) {
2420-
assert_eq!(x.total_cmp(&y), std::cmp::Ordering::Less);
2425+
assert_eq!(x.total_cmp(&y), Ordering::Less);
24212426
}
24222427
fn check_gt<T: Float + TotalOrder>(x: T, y: T) {
2423-
assert_eq!(x.total_cmp(&y), std::cmp::Ordering::Greater);
2428+
assert_eq!(x.total_cmp(&y), Ordering::Greater);
24242429
}
24252430

24262431
check_eq(f64::NAN, f64::NAN);

0 commit comments

Comments
 (0)