Skip to content

ENH: Add constexpr overloads for itk::Math::abs#5797

Open
hjmjohnson wants to merge 1 commit intomainfrom
constexpr-math-operations
Open

ENH: Add constexpr overloads for itk::Math::abs#5797
hjmjohnson wants to merge 1 commit intomainfrom
constexpr-math-operations

Conversation

@hjmjohnson
Copy link
Member

@hjmjohnson hjmjohnson commented Feb 12, 2026

Include integral and floating-point support

Refactored itk::Math::abs c++ constexpr,
supporting both integral and floating-point types. Improved compile-time
evaluation with constexpr. Enhanced test coverage for itk::Math::abs.

PR Checklist

  • No API changes were made (or the changes have been approved)
  • No major design changes were made (or the changes have been approved)
  • Added test (or behavior not changed)

@github-actions github-actions bot added type:Enhancement Improvement of existing methods or implementation type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct area:Core Issues affecting the Core module labels Feb 12, 2026
@hjmjohnson hjmjohnson marked this pull request as draft February 12, 2026 20:47
@hjmjohnson hjmjohnson force-pushed the constexpr-math-operations branch from 4fcc6d0 to 0d1a52b Compare February 12, 2026 21:17
Copy link
Member

@dzenanz dzenanz 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 on a glance.

@hjmjohnson hjmjohnson force-pushed the constexpr-math-operations branch 2 times, most recently from eb506bd to 60ab154 Compare February 13, 2026 00:14
@hjmjohnson hjmjohnson marked this pull request as ready for review February 13, 2026 12:05
@hjmjohnson hjmjohnson force-pushed the constexpr-math-operations branch 2 times, most recently from a19ef23 to d71da7d Compare February 13, 2026 12:53
@hjmjohnson hjmjohnson force-pushed the constexpr-math-operations branch from d71da7d to 236f95f Compare February 13, 2026 13:09
Include bool, integral, and floating-point support

Refactored `itk::Math::abs` with constexpr for bool, integer
and floating point types.

Conditionally use `std::abs` within itk:: when constexpr is
available (i.e. c++23 and greater), or revert to custom
constexpr code for c++17-c++23.

Maintain backward compatibility with pre-ITKv6.0 computations
while enabling explicit `std::abs` usage for modern standards.

Signed types are promoted to unsigned return types for integers.

Remove "using std::abs" which was polluting the itk namespace
with hard to interpret intent,  provide explicit support
for all itk types with the itk::safe_abs().  itk::safe_abs
is constexpr compatible for bool, floating, and integer types.
@hjmjohnson hjmjohnson force-pushed the constexpr-math-operations branch from 83c0d97 to 3cc3f4a Compare February 13, 2026 18:50
Copy link
Member

@thewtex thewtex left a comment

Choose a reason for hiding this comment

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

🔥

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:Core Issues affecting the Core module type:Enhancement Improvement of existing methods or implementation type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants