Skip to content

Move abs() from SimdFloat to SimdBase, implement it on integers - #371

Merged
Shnatsel merged 1 commit into
linebender:mainfrom
Shnatsel:abs
Sep 6, 2026
Merged

Move abs() from SimdFloat to SimdBase, implement it on integers#371
Shnatsel merged 1 commit into
linebender:mainfrom
Shnatsel:abs

Conversation

@Shnatsel

@Shnatsel Shnatsel commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

This is technically API-breaking so I'd like to get it done before v1.0

Implements wrapping semantics, same as i32::abs(). We can add a saturating variant later, since it doesn't require API changes.

OpSig::Unary,
"Compute the absolute value of each element.\n\n\
Unsigned integers are unchanged. Signed integers use wrapping absolute value: \
the minimum representable value remains unchanged. This matches `i32::abs()`.\n\n\

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Probably wrapping_abs would be the better comparison, right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Since we don't panic in debug mode, yes, that's more accurate. I think it's less clear though.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm not married to it, so I'll change it if you insist.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Not insisting 😄 as you want

@Shnatsel
Shnatsel added this pull request to the merge queue Sep 6, 2026
Merged via the queue into linebender:main with commit 850adca Sep 6, 2026
22 checks passed
@Shnatsel
Shnatsel deleted the abs branch September 6, 2026 17:27
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