I create a simple array of 100 equal values of 0.1 floats and sum them up using the following straightforward code:
1 2 3 4 5 6 7 8 9 10 11 |
#include <array> #include <numeric> #include <iostream> int main() { std::array<float, 100> a; std::fill(a.begin(), a.end(), 0.1f); std::cout << std::accumulate(a.begin(), a.end(), 0) << std::endl; return 0; } |
The expected result is 10. Why this simple program prints the result 0 ?