Skip to content

cmp: min/max is inconsistent with partial_min/max on certain edge cases #23687

Closed
@HeroesGrave

Description

@HeroesGrave

cmp::partial_min(a, b) returns a if a <= b, while cmp::min(a, b) return a if a < b.
Same story with partial_/max.

This will cause unexpected behaviour when a < b == a > b == false, but a != b (ie: ord treats them as equal, but they aren't equal). For simple types this isn't an issue because if ord treats them as equal they are usually equal. However, for more complex types, partial_min(a, b) != min(a, b) etc. which will cause subtle errors and a lot of pain tracking down the cause.

The behaviour of the partial_ variants in this case seems more correct to me. When the two arguments are equal, it is more intuitive to return the first.

Not sure if this needs an RFC to go through.

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