-
-
Notifications
You must be signed in to change notification settings - Fork 2.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
Proposal: Rename @trunc and @truncate #3788
Comments
Good catch, I hadn't noticed we had such similar names. One thing to consider, although it doesn't necessarily mean not to do this, is that It's no coincidence - Zig semantics allows the compiler to replace calls to this builtin with calls to libc (when libc is being linked), as well as peephole optimizations that turn sections of code into calls to this builtin. When libc is not being linked Zig puts I like the For |
One extra thing: if it's only going to be for floats, lets call it Then we can "float round the ceiling" ;) |
I like the idea of an explicit |
I lean toward either obviously named functions
or obviously named enums
Both are very clear, thanks to keystrokes! Eliminates ambiguous As for |
I believe that |
A
|
There's both
@trunc
and@truncate
. I think at least one of them should change name, but probably both?Simplest solution:
@trunc
->@floatTruncate
@truncate
->@intTruncate
Alternatively (as suggested by @daurnimator):
Replace
@trunc/round/ceil/floor
and provide a single builtin that takes an enum:@round(comptime T, value: T, mode: enum {Floor, Ceil, TowardsZero, AwayFromZero})
I think I prefer that solution for
@trunc
, but I feel like@intTruncate
might be good anyway, to make it clearer.The text was updated successfully, but these errors were encountered: