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)

I mean this is always accurate?(value is an int variable)

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

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.