From a friend of mine, I heard that the pow function is slower than its equivalent in simply multiplying the base by itself, the amount of times as its exponent. For example, according to him,
#include <stdio.h>
#include <math.h>
int main () {
double e = 2.71828
e2 = pow (e, 2.0)
printf("%le", e2)
}
is slower than
#include <stdio.h>
int main() {
double e = 2.71828
e2 = e * e
printf("%le", e2)
}
As a novice, I would think they both compile at the same speed, and by the same logic, I would prefer the former for its typical pithiness. So, why is the former block of code slower than the latter one?