Skip to content

OrderedFloat PartialOrd implementation should match Ord implementation #34

@cake4289

Description

@cake4289

Otherwise OrderedFloat is not ordered at all, breaking the assumptions of any algorithm that uses it.

The documentation for Ord says

Implementations of PartialEq, PartialOrd, and Ord must agree with each other. It's easy to accidentally make them disagree by deriving some of the traits and manually implementing others.

The following test fails:

extern crate ordered_float;

use std::f64::NAN;
use ordered_float::OrderedFloat;

#[test]
fn less_than_nan() {
    let x = OrderedFloat(1.0);
    let y = OrderedFloat(NAN);
    assert!(x < y);
}

None of the tests in this crate cover using the comparison operators; they all use Ord::cmp directly. This should be fixed. The current code is unsound and could lead to unsafety.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions