The recent PR 5802 has triggered a bunch of new warnings in RTK because “std::abs() returns the absolute value in the same type as the input, itk::Math::Absolute() returns the absolute value in the unsigned equivalent of the input type”. Looking closely at the warning
/home/srit/src/rtk/dashboard_tests/RTK/include/rtkJosephForwardProjectionImageFilter.hxx:178:1: required from here
[CTest: warning matched] /home/srit/src/rtk/dashboard_tests/RTK/include/rtkJosephForwardProjectionImageFilter.hxx:383:28: warning: comparison of integer expressions of different signedness: 'int' and 'unsigned int' [-Wsign-compare]
383 | for (int i{ 0 }; i < itk::Math::Absolute(fs - ns) - 1; ++i)
| ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I think the behavior of the new itk::Absolute is undesirable in these cases and I am concerned this is not obvious to the user as the legacy itk::Math::abs calls itk::Math::Absolute. In this code, if fs equals ns, then you’d prefer itk::Absolute to return an int and not an unsigned int. So my questions are:
- If you agree, should we keep the new
itk::Absoluteas is? - If yes, what is in your opinion the best option here? I can think of a
static_castof the value returned byAbsoluteor makingiunsignedand moving the-1to the left-hand side, but I find both much less readable than the original version… Any other suggestion?