I am working at porting a scientific C++ application
which needs floating point reproducibility to PowerPC
using PearPC 0.4 under Windows XP (x86), with Darwin
7.0.1 as a guest.
I found a problem with rounding from double to float.
More exactly, in src/cpu/cpu_generic/ppc_fpu.h in
functions ppc_fpu_round and ppc_fpu_round_single, for
switch case FPSCR_RN_NEAR, the decision to round is
made using only 3 fractional bits. This leads to a
problem in the case of round to nearest, when these
three bits are 100, and rounding is done to make the
rounded bit even.
The IEEE 754 standard says that the decision to make
the rounded bit even is only done when the fractional
part is EXACLTY half (100000000....), not only a few
bits; otherwise, it must round to the nearest value.
Ran on x86, under mingw, the attached C program rounds
correctly. However, under PearPC, the C program rounds
incorrectly (compiled with gcc, no special options).
It may be that the behavior is intentional, to favor
speed; I hope that the real PowerPC is IEEE compliant.