If you are using g ++, try compiling both versions with -Wconversion (or -Wfloat-conversion ).
Note that the <cmath> version generates a warning:
main.cpp: 14: 7: warning : conversion to long long int from __gnu_cxx :: __ enable_if :: __ type {aka double} may change its value [-Wfloat conversion] c = abs (a) + abs (b) ;
So far, the version of <cstdlib> compiled without warning.
This is because in <cmath> , abs() is defined as 1 :
float abs(float); double abs(double); long double abs(long double);
In <cstdlib> it is defined as 1 :
int abs(int); long abs(long); long long abs(long long);
1 Integer versions of abs() defined in <cmath> since C ++ 17.
sergej
source share