Beware of the difference between ::abs and std::abs

By , last updated August 26, 2019

When you need to use the absolute value from a variable, use std::abs (usually residing in ). If you’re certain you’ll be dealing with floating point variables, use std::fabs.

If you only use ::abs with floating point variables, you’ll risk an implicit cast to an integral value (short, int, long). This won’t be converted to std::abs even if you include using namespace std;

Be safe, use ::fabs, std::abs or std::fabs, but not ::abs.