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*: James E Wilson <wilson at specifixinc dot com>*To*: Chris Lattner <sabre at nondot dot org>*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 15:32:22 -0800*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>

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. 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. 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. 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. -- Jim Wilson, GNU Tools Support, http://www.SpecifixInc.com

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

**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

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

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