Why does gcc -O1 affects std::rint()?

81 views Asked by At

Why does the following code produce -1 when compiled using g++ -O1? My gcc version is 13.2.1.

#include <iostream>
#include <cmath>
#include <cfenv>

using namespace std;

int main() {
    fesetround(FE_DOWNWARD);
    cout << rint(-1.6) << endl;
    return 0;
}
1

There are 1 answers

0
konchy On BEST ANSWER

For GCC, You should compile your program with -frounding-math if your program may change the FP rounding mode dynamically, or may be executed with a non-default rounding mode

godbolt