#include <cstdio>
int main(void)
{
int val = 500;
printf("%d\n", (int)((long double)val / 500));
printf("%d\n", (int)((long double)500 / 500));
}
Obviously it should output 1 1. But if you compile it with -Ofast, it will output 0 1, why?
And if you change 500 to other values (such as 400) and compile with -Ofast, it will still output 1 1.
Compiler explorer with -Ofast: https://gcc.godbolt.org/z/YkX7fB
It seems this line causes the problem.
