The double precision expression of
(37.0 * 100.0) / 34.0
yields three different results, depending whether it is calculated by mathieeedoubbas.library, an 68k FPU or a PPC FPU. The rounding mode should always be "round to nearest", as required by ISO-C.
Here is a small test program:
Code:
void
fpEq (double x, double y)
{
if (x != y)
exit (1);
}
void
fpTest (double x, double y)
{
double result1 = (35.7 * 100.0) / 45.0;
double result2 = (x * 100.0) / y;
fpEq (result1, result2);
}
main ()
{
fpTest (35.7, 45.0);
exit (0);
}
result1
in this test is usually calculated by the compiler, and depends on whether the compiler itself uses an FPU, or is a cross-compiler.
My oberservation is that
result2
is evaluated as $4053d55555555554 when using the mathieeedoubbas.library for
IEEEDPMul
and
IEEEDPDiv
. A 68k FPU (tested with 68060) evaluates it as $4053d55555555555, using
fmul.d
and
fdiv.d
. While a PPC- or x86-based cross-compiler thinks
result1
must be $4053d55555555556! The test fails.
What is correct?
I can confirm that
FPCR
was 0 while running the test with 68060 FPU, so it should have been in round-to-nearest mode, as required by ISO-C. But perhaps the rounding mode has nothing to do with it, and this is just a matter of precision, which is higher in the 68k FPU than in the PPC or x86 FPU?
Anyway, the mathieeedoubbas result looks most incorrect to me. Is that a bug (OS3.9, didn't check OS3.2 yet)? What rounding mode does mathieeedoubbas use? Can you even change it?
EDIT: Using John R. Hauser's portable IEC/IEEE Softfloat library yields $4053d55555555556. Whatever that means...