Jan 27, 2013 at 4:32pm UTC
this is a simple question. the pow function in math.h returns double. is there any problem using it with integer base,exponents like this: value=(int)pow(base,exponent);
I mean this is always accurate?(value is an int variable)
Jan 27, 2013 at 6:49pm UTC
I would use
value = (int)(pow(base,exponent)+0.5);
The reason? casting to int does a truncate.
i.e, 3.9999999999999999 would become 3.
There could be a little inaccuracy in the returned double and if it is slightly under you will get the wrong number
Topic archived. No new replies allowed.
General C++ Programming
© cplusplus.com, 2000-2013 - All rights reserved -
Spotted an error? contact us