Closed
Description
#include <cmath>
#include <cfenv>
#include <functional>
#include <iostream>
int main()
{
std::fesetround(FE_UPWARD);
float v = 0.125;
float v1 = (float)std::nearbyint((float)(0.125));
float v2 = (float)std::rint ((float)(0.125));
std::cout << "nearbyint(0.125) = " << v1 << std::endl;
std::cout << "rint(0.125) = " << v2 << std::endl;
return (v1+v2);
}
$ clang++ test.cpp
nearbyint(0.125) = 1
rint(0.125) = 1
$ clang++ -O2 test.cpp
nearbyint(0.125) = 0
rint(0.125) = 0
As above show, the result using -O2 is different from using -O0.