Why does gcc compiler output pow(10,2) as 99 not 100?

c++, gcc

Solution

Because of integer truncation. `pow()` returns a floating point value, and due to floating point arithmetic, it is probably ~ `99.999...`; however, due to integer truncation, even `99.999...` gets truncated down to 99.

Problem

``` #include <iostream.h> #include <math.h> int main() { int j=2; int output; output=pow(10,j); cout<<output; return 0; } ``` I wrote above code to gcc 12 compiler and got the output 99 instead 100. I don't get the valid reason while searching on various sites. Is there any compiler problem?

Original source

Related problems