Skip to main content

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

Compares two values using IEEE 754 total ordering.

This ordering is defined for all floating-point values, including NaN. The ordering is: -NaN < -Inf < ... < -0 < +0 < ... < +Inf < +NaN.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<K: NumKernel> TotalCmp for RealValidated<K>

Source§

impl<T: NativeReal> TotalCmp for T