I'm observing incorrect (IMO) rounding behaviour on some platforms as follows:
Calculate the value of log(2) under rounding modes to FE_DOWNWARD and FE_UPWARD (see <fenv.h>). In all cases I've seen, the rounded downward result is less than the rounded upward result, which is what I would expect (result is inexact).
Now using the same rounding modes, call exp with each result. Since exp is monotonically increasing (slope is ~2 in the area of interest), I would expect the these results to be even further apart. But on some platforms tested, the two results from exp are equivalent.
Here's a simple test program:
#include <stdio.h>
#include <math.h>
#include <fenv.h>
int main(void) {
fesetround(FE_DOWNWARD);
double xlo = log(2);
double xxlo = exp(xlo);
printf("xlo=%.16e xxlo=%.16e\n",xlo,xxlo);
fesetround(FE_UPWARD);
double xhi = log(2);
double xxhi = exp(xhi);
printf("xhi=%.16e xxhi=%.16e\n",xhi,xxhi);
printf("Delta x=%.16e\n",xhi-xlo);
if (xxlo == xxhi)
printf("FAIL\n");
else
printf("Delta xx=%.16e\n",xxhi-xxlo);
return 0;
}
One (good) result on Xeon E5520 @ 2.27GHz:
xlo=6.9314718055994528e-01 xxlo=1.9999999999999997e+00
xhi=6.9314718055994540e-01 xxhi=2.0000000000000005e+00
Delta x=1.1102230246251566e-16
Delta xx=6.6613381477509393e-16
Other processors that have passed the test: AMD Ryzen 9 3950X, Intel i7-5557U, Intel i7-3770, Intel m7-6Y75.
But a couple have reportedly failed (xxlo==xxhi): Intel E5-2650 and AMD EPYC 7401, coincidentally both server class machines. I don't have direct access to those but running the test at https://repl.it/languages/c also fails:
clang version 7.0.0-3~ubuntu0.18.04.1 (tags/RELEASE_700/final)
clang-7 -pthread -lm -o main main.c
./main
xlo=6.93147180559945286e-01 xxlo=2.00000000000000000e+00
xhi=6.93147180559945398e-01 xxhi=2.00000000000000000e+00
Delta x=1.11022302462515655e-16
FAIL
I'm not so much interested in the actual precision of the results, but more in the relative values. So am I missing something, or is this just wrong? And if it's wrong, is it hardware rounding error or issues with the software math libraries, or even the compiler/settings? I'm also interested in collecting any results from running the simple test to see if any additional conclusions can be drawn from that data.