Hi all.
I've had a hard time writing the typical program that converts a string containing only digits. After too much time than expected working on it I discovered this issue regarding function pow. Just take this code and try it:
I get this result:
10 2
base = 10
exponent = 2
power = 100
power = 99
If you, instead, declare power as double, then you get identical results as expected.
It looks like a rounding issue if you use an int, and suppose an automatic casting type from double to int
I would say there is something wrong with this function (pow)
Someone has any information about this?
Yes. That warning was the one that pointed me to the "solution". If, in my code, you just declare power as double, everything is fine.
So, the thing is, what is happening with automatic type conversion?. I mean, if you have 4.34, and you try to use it as an integer, the compiler performs the automatic conversion and you get 4. But something is extrange here, it looks like the power is 99.99999999 (any amount of 9's), and it is converted to int returning 99. isn't it?
By the way, I've done this test in eclipse wascana, using mingw as a toolchain and everything on windows XP profesional sp3