Skip to content
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

Add abs for all signed ints #1854

Merged
merged 5 commits into from
Sep 4, 2023
Merged

Add abs for all signed ints #1854

merged 5 commits into from
Sep 4, 2023

Conversation

chipshort
Copy link
Collaborator

Pulled out of #1807

Copy link
Member

@webmaster128 webmaster128 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Could you add a few tests for those?

Copy link
Member

@webmaster128 webmaster128 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. We can also test zero:

assert_eq!(Int512::zero().abs(), Int512::zero());

One other thought: Is there any standard way to do a sigened -> unsigned conversion via abs? Would you do abs_diff with zero?

@chipshort
Copy link
Collaborator Author

Not via abs, but there is unsigned_abs. I think it would be functionally equivalent to abs_diff with zero (probably saves a few instructions)

@webmaster128
Copy link
Member

but there is unsigned_abs.

Oh, nice. This is even available for primitive types. Can we add this too here? It's nice as it cannot panic.

@chipshort chipshort merged commit a3fa676 into main Sep 4, 2023
3 checks passed
@chipshort chipshort deleted the signed-ints-abs branch September 4, 2023 09:01
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.

2 participants