C++ std::accumulate doesn't give the expected sum

前端 未结 5 1204
长发绾君心
长发绾君心 2020-12-05 13:18
double numbers[ ] = { 1, 0.5 ,0.333333 ,0.25 ,0.2, 0.166667, 0.142857, 0.125,
                       0.111111, 0.1 } ;
std::vector doublenumbers ( numb         


        
5条回答
  •  抹茶落季
    2020-12-05 13:32

    You're calling accumulate with 0 as the init argument, so it'll accumulate using integer maths. Use 0.0 instead.

提交回复
热议问题