You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2021/05/13 03:39:01 UTC

[GitHub] [arrow] cyb70289 commented on pull request #10274: ARROW-12685: [C++][Compute] Add unary absolute value kernel

cyb70289 commented on pull request #10274:
URL: https://github.com/apache/arrow/pull/10274#issuecomment-840269487


   Thanks @edponce for deep investigation.
   
   From std::abs() [document](https://en.cppreference.com/w/cpp/numeric/math/abs), it is *UB* if input is `numeic_limit::min()`. So compiler can do whatever optimization that doesn't violate the standard.
   
   `Computes the absolute value of an integer number. The behavior is undefined if the result cannot be represented by the return type. `
   
   For checked abs, you can check `arg == min()` before calling `std::abs()`.
   For non-checked abs, thought compiler generated code is safe, I think it's better to go back to `return v < 0 ? (~(unsigned)v + 1) : v;` approach.


-- 
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:
users@infra.apache.org