Why is pow(int, int) so slow?

pow() works with real floating-point numbers and uses under the hood the formula pow(x,y) = e^(y log(x)) to calculate x^y. The int are converted to double before calling pow. (log is the natural logarithm, e-based) x^2 using pow() is therefore slower than x*x. Edit based on relevant comments Using pow even with integer exponents may … Read more

Ambiguous overload call to abs(double)

The header <math.h> is a C std lib header. It defines a lot of stuff in the global namespace. The header <cmath> is the C++ version of that header. It defines essentially the same stuff in namespace std. (There are some differences, like that the C++ version comes with overloads of some functions, but that … Read more