-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
std: lessThan and greaterThan between signed and unsigned #3001
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm OK to merge this right now, but I want to propose an alternate API:
- make Compare enum public and rename to CompareOperator
- add EQ and NE to CompareOperator enum
pub fn compare(a: var, comptime op: CompareOperator, b: var) bool
- delete
lessThan
,lessThanOrEqual
,greaterThan
, andgreaterThanOrEqual
I'll move this back to 0.5.0 if feedback is addressed |
f381bc9
to
ae8c98a
Compare
Maybe pub const CompareOperator = enum {
lessThan,
lessThanOrEqual,
equal,
greaterThan,
greaterThanOrEqual,
}; ? |
@data-man Yes, .equal is also useful, I didn't think of that. |
Oh! I missed |
It is a deviation from C, but I think we should consider making this the behavior of the operators. See ziglang#2133
@shawnl Please also add |
@data-man |
Sure.
|
We could even support these comparisons between floats and integers, and floats of different bit widths. The only case I'm not sure about is when you have an integer that would round to a specific float (with a positive exponent) but is a different value, I think that should return not equal. |
Current plan for the language specification (#75) is to allow comparisons between floats & ints. |
It is a deviation from C, but I think we should consider making this the behavior
of the operators. See #2133
With vectors this behavior can be kinda expensive if the type sizes are 8, 16, 32, 64. (this does not implement vectors, but it is easy to do so with my other patch set). But premature optimization is the root of all evil, and I think its better to prefer readability of the code, and then catch minor performance stuff later.
This PR is partially to spark discussion, and demonstrate well-defined behavior.