-
Notifications
You must be signed in to change notification settings - Fork 135
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
[feature request] total_cmp for num_traits::Float #256
Comments
Is there a generic way to write a default implementation? Otherwise, adding a trait method is a breaking change. |
To my knowledge there is no trivial built-in generic way. |
Then I suppose this will need to be a standalone trait. Something like:
That could even have impls for integers. In theory, we could have a blanket impl for all |
Incidentally, half provides implementations of As a separate constraint which could be imposed upon generic types, it would be useful in the rare numerical algorithms which necessitate sorting of floating point numbers (e.g. isotonic regression). The inevitable bikeshedding: |
We could further distinguish this from |
|
@andrewjradcliffe Would you be interested in writing that pull request? |
Just saw this today -- I'm not great about checking notifications ._. |
295: `TotalOrder` trait for floating point numbers r=cuviper a=andrewjradcliffe Define an orthogonal trait which corresponds to the `totalOrder` predicate the IEEE 754 (2008 revision) floating point standard. In order to maintain coherence, the bounds on `TotalOrder` should most likely be `TotalOrder: Float` (or `TotalOrder: FloatCore`). Without type constraints, `TotalOrder` could be defined on, well, anything. Though slightly ugly, one way to deal with this is to define two traits, `TotalOrderCore: FloatCore` and `TotalOrder: Float`. On the other hand, `Inv` has no such constraints (due to the possibility of a meaningful implementation on rational numbers). If the crate designers could weigh in on whether to introduce constraints, that would be helpful. Resolves: [issue#256](#256) Co-authored-by: Andrew Radcliffe <[email protected]> Co-authored-by: Josh Stone <[email protected]>
295: `TotalOrder` trait for floating point numbers r=cuviper a=andrewjradcliffe Define an orthogonal trait which corresponds to the `totalOrder` predicate the IEEE 754 (2008 revision) floating point standard. In order to maintain coherence, the bounds on `TotalOrder` should most likely be `TotalOrder: Float` (or `TotalOrder: FloatCore`). Without type constraints, `TotalOrder` could be defined on, well, anything. Though slightly ugly, one way to deal with this is to define two traits, `TotalOrderCore: FloatCore` and `TotalOrder: Float`. On the other hand, `Inv` has no such constraints (due to the possibility of a meaningful implementation on rational numbers). If the crate designers could weigh in on whether to introduce constraints, that would be helpful. Resolves: [issue#256](#256) Co-authored-by: Andrew Radcliffe <[email protected]> Co-authored-by: Josh Stone <[email protected]>
With
total_cmp()
being stabilized forf32
andf64
, could this be included in the floating point trait? It's quite a convenient method for sorting generic floating point types.The text was updated successfully, but these errors were encountered: