From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28129 invoked by alias); 14 Feb 2006 15:45:54 -0000 Received: (qmail 27984 invoked by uid 48); 14 Feb 2006 15:45:51 -0000 Date: Tue, 14 Feb 2006 15:45:00 -0000 Message-ID: <20060214154551.27983.qmail@sourceware.org> X-Bugzilla-Reason: CC References: Subject: [Bug libgcj/16122] gij - Incorrect result due to computations in extended precision on x86 In-Reply-To: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "aph at gcc dot gnu dot org" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2006-02/txt/msg01546.txt.bz2 List-Id: ------- Comment #4 from aph at gcc dot gnu dot org 2006-02-14 15:45 ------- A bit more explanation. The problem is caused by the fact that 9007199254740994.0 + 0.9999847412109375 is carried out in extended precision, and the result is rounded to 9007199254740995. In double precision, the result of this calculation is rounded to 9007199254740994. When the extended-precision value is rounded to double for storing, it is rounded (again) to 9007199254740996. So, double rounding leads gij to return a value of d that is 2.0, whereas it should be 0.0. Note however, that the true accurate value for d, calculated at infinite precision, is 1-(2^-16). So, the absolute error for gcj is 1+(2^-16) and the absolute error with correct rounding is 1-(2^-16). (I'm not surprised this hasn't been reported as a problem with any real applications!) It might be worth setting the floating-point precision of gcj to double, but that would only fix the double-precision case, and I presume we'd still have the same double rounding problem for floats. And in any case, I do not know if libcalls would be affected by being entered with the FPU in round-to-double mode. We might end up breaking things. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16122