cyb70289 edited a comment 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 (no UB), I think it's better to go back to `return v < 0 ? (~(unsigned)v + 1) : v;` approach. Though the assembly code is exactly the same, compiler may decide to change behaviour in the future. -- 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]
