Skip to content

std::cmp::max vs std::num::Float vs NaN #852

@steveklabnik

Description

@steveklabnik

Issue by pornel
Saturday Jan 31, 2015 at 18:28 GMT

For earlier discussion, see rust-lang/rust#21816

This issue was labelled with: A-libs in the Rust repository


It's werid that std::cmp::max can't compare f64 numbers. I know that strictly speaking IEEE floats don't have total order this function expects, but still it's surprising (and partial_max is awkward to use).

And there's std::num::Float::max which works with f64 just fine (the docs don't even say how NaN is handled).

It bugs me that the two versions of max are not consistent in their strictness, and that the first-and-most-obvious max function in the stdlib "doesn't work" with a basic type in the language.

My suggestion:

  • Rename the max version that only allows Ord to something else, like total_max or strict_max.
  • Implement std::cmp::max for floating point numbers, so that a.max(b) is consistent with max(a,b).

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-libs-apiRelevant to the library API team, which will review and decide on the RFC.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions