In C++ the compiler reminds me that subtracting unsigned values is unsigned and so calling abs() is pointless:
uint64_t a, b;
if (std::abs(a - b) > 10) {
std::cout << "Divergence achieved!" << std::endl;
}
OK, I understand that subtraction is addition, and I know in my instance that the numbers will be less than 2^63, so I static_cast
to int64_t
. But the point of calling abs
was to avoid writing
if (a - b > 10 || b - a > 10) {
std::cout << "Divergence achieved!" << std::endl;
}
Is there a more idiomatic way to do this?