Skip to content

Use total_cmp for floats#4

Draft
DanikVitek wants to merge 1 commit into
codereport:mainfrom
DanikVitek:rust
Draft

Use total_cmp for floats#4
DanikVitek wants to merge 1 commit into
codereport:mainfrom
DanikVitek:rust

Conversation

@DanikVitek
Copy link
Copy Markdown

@DanikVitek DanikVitek commented Jan 7, 2026

Hi there. I was experimenting on a solution that would be more robust for floats (in case of NaN values). There is a method defined for floats in std, called total_cmp, that allows for total ordering of NaN values, but I had to implement a custom trait to use the is_arithmetic_progression for all applicable types.

Unfortunately, the blanket impl<T: Ord> TotalOrd for T is not possible to be used together with a separate impl for floats, due to the "possible future implementation of Ord on {float}" (which will never happen, but oh well). I guess this could probably be solved with the trait specialization nightly feature...

To reduce repetitions, I've made the macro_rules! declarative macros which generate the impl blocks for all integers and floats. The impl_int macro could also be used for any other impl Ord type, but only manually...

I'm not sure the solution is that good to be merged, so just a draft PR.

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.

1 participant