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 checked_* elementwise arithmetic operations for {I,U}Vec{2,3,4} #596

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

Conversation

Dentosal
Copy link

For integer vectors, it's often useful to check if an operation would overflow. This helps with writing more robust code without having to do checks with if statements. Since we already have wrapping_ and saturating_ from Rust standard library, I figured having checked_ would be welcome as well.

The test code is sadly very repetitive, as it's not generated from a template. Hopefully I got it all copy-pasted correctly!

@@ -735,6 +735,43 @@ macro_rules! impl_vec2_signed_integer_tests {
assert_eq!((-$vec3::ONE).signum(), -$vec3::ONE);
});

glam_test!(test_checked_add, {
assert_eq!($vec3::MAX.checked_add($vec3::ONE), None);
Copy link
Owner

@bitshifter bitshifter Jan 28, 2025

Choose a reason for hiding this comment

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

these should be using $vec2 (the existing test_signum code above looks wrong)

@@ -2161,7 +2240,7 @@ mod i8vec4 {
);
});

glam_test!(test_wrapping_sub, {
glam_test!(test_wrapping_m, {
Copy link
Owner

Choose a reason for hiding this comment

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

This looks like an unintended change?

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