-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
libc: implement common abs
for various integer sizes
#23893
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
base: master
Are you sure you want to change the base?
Conversation
} | ||
|
||
fn abs(a: c_int) callconv(.c) c_int { | ||
return if (a > 0) a else -a; |
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.
Why this way instead of return @abs(a)
?
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 think to remember to have read somewhere that an implementation similar to musl is recommended. @abs
didn't come to my mind
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.
There is no such constraint. As long as it's functionally compatible with the musl implementation, you're free to implement it in a more "Ziggy" way.
That means you can delete the duplicate libc implementations. |
e730278
to
4bbb5df
Compare
_ = @import("c/inttypes.zig"); | ||
_ = @import("c/stdlib.zig"); |
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.
These should be moved outside this check, and appropriate checks should be added around the @export
s instead.
Context: #23847 (comment)
Implemented common libc functions:
abs
imaxabs
labs
llabs
abs functions for floating point numbers are already implemented in compiler_rt.