in c++, std::abs() can be used for float and double. see http://www.cplusplus.com/reference/cmath/abs/