This is the mail archive of the
`gcc@gcc.gnu.org`
mailing list for the GCC project.

Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|

Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |

Other format: | [Raw text] |

*From*: Chris Lattner <sabre at nondot dot org>*To*: James E Wilson <wilson at specifixinc dot com>*Cc*: Richard Henderson <rth at redhat dot com>,Phil Prentice <philp dot cheer at btinternet dot com>, gcc at gcc dot gnu dot org,mike at stec dot clara dot co dot uk, gcc-help at gcc dot gnu dot org*Date*: Tue, 18 Jan 2005 17:50:55 -0600 (CST)*Subject*: Re: Floating point problems (accuracy).*References*: <Pine.LNX.4.61.0501181533190.13706@nondot.org> <20050118222752.GA5163@redhat.com> <Pine.LNX.4.61.0501181629370.14907@nondot.org><1106091142.25652.52.camel@aretha.corp.specifixinc.com>

On Tue, 2005-01-18 at 14:31, Chris Lattner wrote:Aren't F1, F2, and F3 identical?

Yes.

The problem case would be something like float Y, Z; float X = (float)Y + (float)Z; and float X = (float)((double)Y + (double)Z) giving different results, because the second one is liable to double rounding error.

Ah, interesting, I did not know that. I guess if you wanted REALLY inefficient code, the way to do this would be to play with the X86 precision register.

Double rounding error can occur when the result of the add is almost exactly half way between two representable float values. Using decimal for convenience, suppose the unrounded result of the add is something like 00...005,4999999999,999 where the first comma represents the rounding point for float, and the second comma represents the rounding point for double. If we round this directly to float, we get 00...005. If we round this to double, we get 00...005,500..00. If we then round this to float, we get 00...006. Thus double rounding can introduce a single bit error in the least significant bit of the result.

I see.

If you are using x87 long double arithmetic, and converting the result to float/double, then you will get double rounding errors. Double rounding errors will be rare, and probably will affect few programs, but it does mean that the results are still not exactly the same as the results you will get on sparc/mips/power/x86_64/etc. If the only problem you have is double rounding, then you are certainly much better off than the current x87 FP gcc support though.

Okay, thanks for the clarification. You're absolutely right, we are susceptible to double rounding errors.

The only way to avoid double rounding is to have separate float, double, and long double arithmetic instructions, which unfortunately the x87 FP unit doesn't have.

I believe changing the precision fields would work, but at some point you're better off using soft-float...

-- http://nondot.org/sabre/ http://llvm.cs.uiuc.edu/

**References**:**Re: Floating point problems (accuracy).***From:*Chris Lattner

**Re: Floating point problems (accuracy).***From:*Richard Henderson

**Re: Floating point problems (accuracy).***From:*Chris Lattner

**Re: Floating point problems (accuracy).***From:*James E Wilson

Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|

Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |