Hard
A NaN guard in a fast-math translation unit
sanitize.cpp is compiled with -O2 -ffast-math; main.cpp is compiled with plain -O2. Both compilers agree on the result. What does the program print?
main.cpp
// sanitize.cpp (built with -O2 -ffast-math)
#include <cmath>
double sanitize(double x) {
if (std::isnan(x)) return 0.0;
return x;
}
// main.cpp (built with -O2)
#include <cstdio>
#include <cstdlib>
double sanitize(double x);
int main() {
std::printf("%f\n", sanitize(std::strtod("nan", nullptr)));
}43 of 44 in Compilers