Skip to content

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

kada49
Copy link
Contributor

@kada49 kada49 commented May 15, 2025

Implemented common libc functions:

  • abs
  • imaxabs
  • labs
  • llabs

abs functions for floating point numbers are already implemented in compiler_rt.

}

fn abs(a: c_int) callconv(.c) c_int {
return if (a > 0) a else -a;
Copy link
Contributor

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)?

Copy link
Contributor Author

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

Copy link
Member

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.

@alexrp
Copy link
Member

alexrp commented May 16, 2025

abs functions for floating point numbers are already implemented in compiler_rt.

That means you can delete the duplicate libc implementations.

@kada49 kada49 force-pushed the common-impl-libc-abs branch from e730278 to 4bbb5df Compare May 17, 2025 09:03
Comment on lines +19 to +20
_ = @import("c/inttypes.zig");
_ = @import("c/stdlib.zig");
Copy link
Member

@alexrp alexrp May 17, 2025

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 @exports instead.

Context: #23847 (comment)

@alexrp alexrp self-assigned this May 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants