Skip to content

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

Closed
@kornelski

Description

@kornelski

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions