trait

PartialOrd — partial ordering

PartialOrd describes a comparison that may be unordered. It returns None for cases such as comparing floating-point NaN with a number. The comparison must agree with the equality semantics. Expected stdout (not executed): None Common mistake: Unwrapping partial_cmp on arbitrary floating-point values without handling NaN.

Formal Syntax & Structure

rust syntaxrust
fn partial_cmp(&self, other: &Rhs) -> Option<Ordering>

Working Example

Example Snippetrust
fn main() {    let a = f64::NAN;    println!("{:?}", a.partial_cmp(&2.0));}
Rust Reference