Difference between exponents for indices in C++



Could someone simply tell me the difference between e, exp and pow. In my program I like to use the indices 2.5x10^-3 for example so which one from above should I use:
2.5*pow(10,-3.0)
or
2.5e-3
or
2.5*exp(-3.0).

Thank you.
1
2
 
2.5e-3 is the built in notation for floating point numbers (float, double, long double) , so use that.

2.5*pow(10,-3.0) is an inefficient way of doing the same thing.

2.5*exp(-3.0). is the same as 2.5 * pow(e, -3.0) where e is Euler's number ~ 2.7182818284590452353602874713527

http://en.cppreference.com/w/cpp/numeric/math/exp
Last edited on
The exp(x) computes e^x http://www.cplusplus.com/reference/cmath/exp/

The pow(y,x) computes y^x http://www.cplusplus.com/reference/cmath/pow/
You can get same result as exp(x) with pow(2.718282, x)

The 2.5e-3 is literal constant http://en.cppreference.com/w/cpp/language/floating_literal

From these we can conclude that 2.5*exp(-3.0) means 2.5xe^-3 which is not 2.5x10^-3, because e != 10.

The 2.5*pow(10,-3.0) is possible, but why evaluate a function when you already know the answer?

The 2.5e-3 is 2.5x10^-3.
Last edited on
Thanks you for the help guys. Really helpful
Registered users can post here. Sign in or register to post.