Why pow(10,5) = 9,999 in C++

前端 未结 8 1733
忘掉有多难
忘掉有多难 2020-11-22 08:55

Recently i write a block of code:

const int sections = 10;

for(int t= 0; t < 5; t++){
   int i = pow(sections, 5- t -1);  
   cout << i << en         


        
8条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-22 09:20

    There must be some broken pow function in the global namespace. Then std::pow is "automatically" used instead in your second example because of ADL.

    Either that or t is actually a floating-point quantity in your first example, and you're running into rounding errors.

提交回复
热议问题