Fix unary pow error handling and test

Reference issue

What does this implement/fix?

Previous MR was developed using a faulty unit test. This patch fixes the test and the error handling routine for pow(float,float).

I applied this better testing methodology to pow(float,int) and discovered other mis-handled edge cases:

  • if the exponent is signed and equal to its lowest value, i.e. NumTraits<int>::lowest(), then std/numext::abs will return a negative number and cause all sorts of mayhem. Introduced safe_abs to cast a signed integer to its unsigned counterpart and apply the absolute value. This is a lot of work to address one edge case per signed integer type, but the actual computational work is still fairly minimal and only needs to be performed once.
  • int_pow may not correctly handle underflow if the exponent is negative. fixed this by moving the reciprocation to the start of the routine. Originally, this was at the end as it was found to be marginally more accurate
  • if the exponent is astoundingly gigantic such that it cannot be stored as a double, then std::pow may return incorrect values. This is addressed in the testing. Likewise with an underflow issue specific to MSVC

Additional information

Edited by Charles Schlosser

Merge request reports

Loading