The NAN in double may cause the inconsistency in the benchmark:
#include <math.h>
#include <stdio.h>
double snippet1(double a, double b) {
if (b < a) // change
return a; // change
else
return b; // change
}
double snippet2(double a, double b) {
if (b > a)
return b;
else
return a;
}
int main() {
double a = 1.25 * 256;
double b = NAN; // 0x7fc00000
double x = snippet1(a, b);
double y = snippet2(a, b);
printf("%f, %f\n", x, y);
return 0;
}
It turns out that x = nan, y = 320.000000.
I suggest change the type from double to int.
The
NANin double may cause the inconsistency in the benchmark:It turns out that
x = nan, y = 320.000000.I suggest change the type from
doubletoint.