-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
define Ord as a total ordering and remove the f32/f64 implementation (similarly, remove the Eq implementation) #10320
Comments
One implication of this is that you could not sort an array of floats |
We could add PartialEq and PartialOrd and make Eq and Ord total |
Need to discuss further. accepted for 1.0. P-backcompat-lang. |
@nikomatsakis: You wouldn't be able to use a |
There's now a |
FWIW, |
One thought: Why is it so hard to implement |
I guess this does not work as well for Eq unless we define the operator |
@nikomatsakis: I think it would be quite strange for |
I think doing this is incredibly important. A sane definition of equality and ordering is required for these traits to be useful for writing correct generic code. If having these for floating point numbers is viewed as important, then we should to implement the IEEE754 total ordering for the built-in comparison operations and these traits. The traditional partial ordering can be provided via a separate set of methods. Without defined requirements, traits are the worst of both worlds. They're more verbose than generics without bounds and aren't enforcing a set of requirements on the type parameters. |
I agree with this. |
Nominating. |
I can try to work on this. My current plan (which might be completely stupid): created |
There needs to be a plan in place for floating point. It's not just a library issue. |
Do you think it's possible for binary comparison on floating points to do total ordering by default? Does anyone know if there's a meeting planned to address this issue in general? |
This issue would benefit from a RFC writeup. (In general, I want to |
@pongad: IEEE754 defines a total ordering predicate, but hardware doesn't implement it. |
I don't think it needs to take more than one step. We can just add the correct definition to |
I personally like to iterate and not do everything at once. Though I do On Wed, Feb 19, 2014 at 11:58 PM, Daniel Micay [email protected]:
|
I don't think it should be left in intermediate states. It should really be done in one pull request to avoid a need to use stage annotations and a compiler snapshot too. The annoying part is obtaining a copy of the IEEE754 standard and correctly implementing the ordering. |
I am rather concerned about defining the normal comparison operators ( Unfortunately, I don't have a good suggestion here. It would be odd for |
@kballard: Having Implementing With the IEEE754 total ordering, |
@thestinger Do you have any evidence for your claims about performance? From what wikipedia says about the IEEE floating point total order predicate, Why are Perhaps And then, perhaps to make it more obvious what's going on, we could rename |
This issue is about removing A I moved the floating point part of the problem to #12434.
It seems equality would be a bitwise comparison. |
Performance-wise, Rust already needs a check for integer division by zero, signed integer division of INT_MIN by -1, overlong shifts, casts to and from floating point types and bounds checks. I don't really think this is really any different - Rust won't be as efficient as C with the default operators, but the weak ordering can still be provided via the |
On Thu, Feb 20, 2014 at 06:36:00PM -0800, Kevin Ballard wrote:
+1
I am currently of the opinion that they should just disagree. I |
I am no longer go to push for this. There is too much opposition to it and the existing design can stay as it is today. |
@nikomatsakis / @kballard There's also a variant where comparison operators on |
@glaebhoerl: Yes, I'm fine with doing that instead. I added the |
I'll send another pull request removing the |
@pongad thank you btw for writing up an RFC. I think perhaps some details were missing, but if I understood correctly, the end goal of what is described is to:
I think there are two seemingly irreconcilable constraints:
The palette of options then becomes:
Precedents: I believe Haskell took approach 1 and Java chose approach 2. Note that in both cases, I am assuming that we implement some total ordering for floats, whatever it is, as that seems strictly better, though opinions may vary here. As I've stated, I am inclined towards option 2, though I see the appeal of option 1. This seems, however, to be related to #11831 -- i.e., to what extent will the Rust types reflect the native hardware behavior, and to what extent will they attempt to emulate something closer to "true" mathematics. |
@nikomatsakis You seem to be at least partly re-hashing the discussion we had in #12442. My understanding of the relevant tradeoffs was here. Further elaboration on my part between two of the options was here. In particular, the proposal I describe at greater length in the latter comment (you can read it as an RFC if you like) is different from both of the options you just described. |
@glaebhoerl indeed. I'm rehashing discussions that have been had numerous times both in other bugs and here and you're right I omitted many choices. Clearly we need to cull some of these bugs! |
#12517 is the issue for @glaebhoerl's suggestion, although with altered naming. |
I agree with the discussion above. Though, I'm a little confused: will the comparison operators on user defined types work off of |
The comparison operators will be tied to |
I'm not quite sure what you mean by the last sentence. Is there some kind of design doc that I can look up? (Sorry if it's in the discussion above and I missed it.) |
I opened #12520 with a list of things to change but I haven't written new documentation for |
@thestinger Thanks! Will take a look. |
@pongad you said: "I'm not quite sure what you mean by the last sentence." To make it clear, the sentence "the Eq trait won't provide any methods itself, trait inheritance will provide them" means something like this: trait DeclareOps<T> {
fn op1(&self, other: &Self) -> T;
fn op2(&self, other: &Self) -> T;
}
trait AddLaws<T> : DeclareOps<T> {
// no new methods; just new laws about how existing methods op1 and op2 must behave.
} |
@pnkfelix I get it now. Thanks a lot! |
The operators will still work, because they are a language feature. This would remove the need for
TotalEq
andTotalOrd
. The current situation is too complex and traits without requirements aren't good traits. These do need some kind of definition, whether it's a total ordering or a weak ordering.Floating point types could still implement these via the IEEE754 total ordering predicate. For equality, it will be as fast as it's just a bitwise comparison. It looks like there's no way to avoid a performance hit for comparisons, but the traditional weak ordering can still be provided via alternate methods.
The text was updated successfully, but these errors were encountered: