Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement NaN propagating minmax with TotalOrder and FloatCore #323

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jdh8
Copy link

@jdh8 jdh8 commented May 11, 2024

Given the IEEE total-ordering predicate and .is_nan(), we can implement NaN propagating minmax, cf. f32::maximum.

I'm not sure if using .is_nan() with trait TotalOrder: FloatCore is the best idea, but I can't think of a better one for now.

@cuviper
Copy link
Member

cuviper commented May 12, 2024

Adding FloatCore is a breaking change, at least -- that was considered in #295, but didn't seem important.

Thematically though, I would expect them to be called total_min and total_max, and follow the full rules of total_cmp. Is there precedent for total-ordered floats that propagate NaN as you have? This is also the opposite of the builtin min/max on floats, which ignore NaN.

@jdh8
Copy link
Author

jdh8 commented May 12, 2024

No, they do not fully follow the rules of total_cmp. The total_cmp predicate is simply a sign-magnitude comparison, where -NaN < -Inf < -finite < -0.0 < +0.0 < +finite < +Inf < +NaN.

The nightly builtin minimum/maximum (not min/max) propagate NaN first (not necessarily one of the inputs) and then compare with total_cmp

@cuviper
Copy link
Member

cuviper commented May 12, 2024

I see -- I wasn't aware of those unstable methods. However, the tracking issue still has a number of unresolved questions, and I'd rather wait to see that stabilized before we try to match their name and behavior.

Even then, a breaking change is still a problem, but you could put where Self: FloatCore on those particular methods instead of the whole trait.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants