Unsolved Why abs wont work on neg val
-
If doing
qint64 n=std::numeric_limits<qint64>::min(); n=qAbs(n); if(n<0) It returns true... But if adding just 1 number its ok. Why is that?
-
@Q139 said in Why abs wont work on neg val:
Why is that?
Because the absolute value of
std::numeric_limits<qint64>::min()
is greater thanstd::numeric_limits<qint64>::max()
. -
See also https://en.cppreference.com/w/cpp/numeric/math/abs :
The behavior is undefined if the result cannot be represented by the return type.