edponce commented on pull request #10274:
URL: https://github.com/apache/arrow/pull/10274#issuecomment-840507006
For such a simple kernel we found:
1. We need to handle overflow case manually because the standard states it
is undefined behavior
2. Compilers can prune checks that test for negative value the result of an
absolute value operation. The purpose of such check is to detect overflow. For
example,
```
result = std::abs(arg);
if (result < 0) {
ERROR(...);
}
return result;
```
becomes `result = std::abs(arg)`. The solution is to first check if input is
a value that will overflow
```
if (arg == std::numeric_limits<T>::min()) {
ERROR(...);
return arg;
}
result = std::abs(arg);
```
3. Tests performing checks for special cases such as `-0.0 == 0.0` should
also check the sign bit, `std::signbit(val)`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]