Skip to content

add constexpr for math operations#5798

Draft
hjmjohnson wants to merge 3 commits intomainfrom
add-constexpr-for-math-operations
Draft

add constexpr for math operations#5798
hjmjohnson wants to merge 3 commits intomainfrom
add-constexpr-for-math-operations

Conversation

@hjmjohnson
Copy link
Member

  • ENH: Add constexpr overloads for itk::Math::abs
  • ENH: Simplify itk::Math prime-related functions with constexpr
  • WIP: Windows is behaving different thatn linux/mac

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:Infrastructure Infrastructure/ecosystem related changes, such as CMake or buildbots 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 13, 2026
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.

Looking good on a glance.

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.
- Removed redundant definitions of `IsPrime` and `GreatestPrimeFactor`
  in `itkMath.cxx` by incorporating template-based implementations in
  `itkMath.h`.
- Improved compile-time evaluation and type safety with `constexpr` and
  `std::enable_if_t`.
- Updated tests to leverage the new `constexpr` `itk::Math` functions.
- Enhanced maintainability by consolidating code and leveraging modern C++ features.
@hjmjohnson hjmjohnson force-pushed the add-constexpr-for-math-operations branch from d2b3b7e to 7583f8e Compare February 13, 2026 19:37
Use GTest framework for testing the math functions.
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:Infrastructure Infrastructure/ecosystem related changes, such as CMake or buildbots 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.

2 participants