1

Using some version of minGW, the following code will print 99.

int high;
high = pow(10,2);
std::cout<<high<<std::endl;

The parameter of pow function is double, but why i get 99? Someone who can tell me the process hidden inside pow function ?

Ryan_Liu
  • 269
  • 4
  • 9
  • 2
    Turn on compiler warnings. That will give you a clue. Second clue: "What every computer scientist should know about floating point." – Raymond Chen Apr 10 '14 at 04:25

1 Answers1

4

Converting a double to an integer truncates the fractional part. pow(10,2) produces a slightly inaccurate result; if it's slightly high, you'll get 100 and if it is slightly low you'll get 99.

Moral: if you mean i*i, write i*i.

rici
  • 234,347
  • 28
  • 237
  • 341