i am running C++ under the GCC compiler on an embedded application. My iterative program (amongst other things) calls the exp function several hundred times. However i find that when using doubles as arguments to the exp function it runs approx 10% faster than when i use floats. surely floats should make the program run faster?
The exp() function takes a double as a parameter and returns a double.
Whether you pass it a float or a double will make no difference on
execution time of the function. The difference lies in that if you pass a
float, the compiler has to generate a code to convert the float to a
double.
If you need a lot of performance and you can afford the memory, use a lookup table to store precomputed values of exp(). But you need to be careful to make sure that accessing the table actually saves you time compared to just calling exp().