TotalCmp

Trait TotalCmp 

Source
pub trait TotalCmp {
    // Required method
    fn total_cmp(&self, other: &Self) -> Ordering;
}
Expand description

Trait for total ordering comparison of floating-point values.

This trait provides a total ordering for floating-point numbers, including special values like NaN and signed zeros. Unlike the standard PartialOrd trait, this comparison always returns a definite ordering.

§Ordering Rules

The total ordering is defined as:

  • Negative NaN < negative infinity < negative numbers < -0.0 < +0.0 < positive numbers < positive infinity < positive NaN
  • NaN values are ordered by their bit representation
  • -0.0 is ordered as less than +0.0

This matches the IEEE 754-2008 totalOrder predicate.

§Examples

use num_valid::functions::TotalCmp;
use std::cmp::Ordering;

let a = -0.0f64;
let b = 0.0f64;
assert_eq!(TotalCmp::total_cmp(&a, &b), Ordering::Less);

let nan = f64::NAN;
let inf = f64::INFINITY;
assert_eq!(TotalCmp::total_cmp(&inf, &nan), Ordering::Less);

Required Methods§

Source

fn total_cmp(&self, other: &Self) -> Ordering

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl TotalCmp for f64

Source§

fn total_cmp(&self, other: &Self) -> Ordering

Implementors§