16th Dec 2017, 11:55 AM
I'm_Groot
I'm_Groot - avatar
9 Answers
+ 7
nice observation, it seems your int type can't handle double precision operations in pow() with older c++ compiler, so you ll need double or at least floats single precision floating point operation btw this is the link I looked for this doubt https://stackoverflow.com/questions/15851636/why-is-my-integer-math-with-stdpow-giving-the-wrong-answer
16th Dec 2017, 12:23 PM
Morpheus
Morpheus - avatar
+ 6
double div !!
16th Dec 2017, 12:00 PM
I'm_Groot
I'm_Groot - avatar
+ 6
but how i deal with it is if(div%10!=0) div+=1;
17th Dec 2017, 5:12 PM
I'm_Groot
I'm_Groot - avatar
+ 5
thx immortal for taking ur time and explaining in comprehensive manner 👍, I got some more clarity
16th Dec 2017, 12:45 PM
Morpheus
Morpheus - avatar
+ 5
tq all
17th Dec 2017, 4:03 AM
I'm_Groot
I'm_Groot - avatar
+ 4
@Immortal int div; div=pow(10,2); //99 so... if(div%10!=0) div+=1; //99+1=100
19th Dec 2017, 2:05 AM
I'm_Groot
I'm_Groot - avatar
+ 4
👍👍
19th Dec 2017, 6:28 AM
I'm_Groot
I'm_Groot - avatar
+ 3
change int to double in "int j = 2..." edit: You can change also to float*
16th Dec 2017, 11:58 AM
Ice
Ice - avatar
+ 3
wow cool question, really unexpected... but yeah its cuz of pow is calculating in floating point precision and the value should be really damn near 100 something like 99.999999.... but then your cast to int simply truncates the decimals to 99. try round(pow(10,2)) and you will see it gives 100
16th Dec 2017, 10:12 PM
---
--- - avatar