On Jan 13, 2005, at 11:32 AM, Charles PARNOT wrote:
Sorry, just a newbie question.
Is it normal that you get slightly different numeric results in
deployment vs developement build in Xcode? (which translates in
different -o flag values in gcc)
Yes, the development build usually doesn't use fused multiply add
instructions. These return different results from ordinary multiply
plus an ordinary add, because there is no rounding step inbetween. (In
a fused multiply add, the multiply produces infinitely precise results,
the addition is done, then the result is rounded down to single or
double precision as appropriate.) Because the fused multiply add
operations are in general more accurate, because of no intermediate
rounding, results will be different.
There are other reasons too, if you are passing stuff like the fast
math flag.
Please note that fused multiply adds can do unpleasant things in
certain cases, especially with complex numbers. The problem is due
asymmetrical rounding:
C1 = Round( Ar * Br )
C2 = Round( Ai * Bi )
result = Round( C1 - C2 )
vs
C1 = Round( Ar * Br )
result = Round( C1 - Ai * Bi )
Note that in the second case, the real product is rounded before the
subtraction while the imaginary product is infinitely precise. If these
are supposed to all cancel out and return a zero result (which they do
in the top case), you'll likely get a small non-zero result in the
second case. Edge case behavior is also different between FMA and
multiply + add, if you need your signed zeros, Infs and NaNs to all
come out right.
However, most of the time the fused multiply add is the right thing to
do for performance and accuracy.