+ 10
How Pow(10,2)=99??
Tell me how?? https://code.sololearn.com/ckh4xjEps9AP/?ref=app
9 odpowiedzi
+ 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
+ 6
double div !!
+ 6
but how i deal with it is
if(div%10!=0)
div+=1;
+ 5
thx immortal for taking ur time and explaining in comprehensive manner 👍, I got some more clarity
+ 5
tq all
+ 4
@Immortal
int div;
div=pow(10,2);
//99 so...
if(div%10!=0)
div+=1;
//99+1=100
+ 4
👍👍
+ 3
change int to double in "int j = 2..."
edit: You can change also to float*
+ 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