Click to See Complete Forum and Search --> : exp with floats and doubles


riched158
June 30th, 2010, 04:00 AM
hi

i am running a program in C++ that calls (amongst other things) the exp function several hundred times. When i use doubles the program runs approx 10% faster than with floats. Can anyone explain why this might be?

cheers
richard

VictorN
June 30th, 2010, 05:10 AM
Which one from a lot of exp types are you using?

//edit: ... and how did you measure and for what build?

riched158
June 30th, 2010, 07:04 AM
hi

i am using c++ under Gcc. As i understand it, in this system the compiler automatically selects the appropiate exp for example expf for a float. One cannot specify which type of exp to use.

http://www.cplusplus.com/reference/clibrary/cmath/exp/

VictorN
June 30th, 2010, 07:12 AM
i am using c++ under Gcc.
...
http://www.cplusplus.com/reference/clibrary/cmath/exp/Well, I don't know how Gcc implements this function but assuming your link:Portability
In C, only the double version of this function exists with this name.
I'd guess that Gcc may use casting/converting operations for floats to double and back to use only this variant: double exp ( double x );
BTW, you haven't answer how you measured... :rolleyes: