0

why is the result of this code after some iterations (10e7) is always 32768? https://godbolt.org/z/GMf4Ps9cP

(x and y are single 32 bit IEEE 754 floating point)

#include <iostream>

int main(){
    float x{0.0};
    float y{0.001};

    for (int i{0}; i<10e7; i++){
        x = x + y;
    }    
    
    std::cout << x << '\n';
    return 0;
}
Progman
  • 16,827
  • 6
  • 33
  • 48
kry23
  • 99
  • 5

0 Answers0