From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 111459 invoked by alias); 14 Apr 2015 17:26:36 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 108143 invoked by uid 55); 14 Apr 2015 17:26:33 -0000 From: "sgk at troutmask dot apl.washington.edu" To: gcc-bugs@gcc.gnu.org Subject: [Bug libquadmath/65757] gfortran gives incorrect result for anint with real*16 argument Date: Tue, 14 Apr 2015 17:26:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libquadmath X-Bugzilla-Version: 4.9.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: sgk at troutmask dot apl.washington.edu X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2015-04/txt/msg01138.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65757 --- Comment #2 from Steve Kargl --- On Tue, Apr 14, 2015 at 01:38:00AM +0000, kargl at gcc dot gnu.org wrote: > Using -fdump-tree-original (and removing the IO code), > one gets > > anintbug () > { > real(kind=16) q1; > real(kind=16) q2; > real(kind=16) q3; > > q1 = 2.33181505644407999969482421875e+14; > q2 = roundq (q1); > q3 = 2.33181505644408e+14; > > } > > So, gfortran is calling the libquadmath routine roundq. > I've changed the component from fortran to libquadmath. > This also appears to fail with all versions of gfortran. > The following patch appears to fix this issue, but I do not know the internals of __float128_t so the bit twiddling may not be right. Index: libquadmath/math/roundq.c =================================================================== --- libquadmath/math/roundq.c (revision 222054) +++ libquadmath/math/roundq.c (working copy) @@ -69,7 +69,7 @@ roundq (__float128 x) } else { - uint64_t i = -1ULL >> (j0 - 48); + uint64_t i = -1ULL >> (j0 - 47); if ((i1 & i) == 0) /* X is integral. */ return x; @@ -77,7 +77,7 @@ roundq (__float128 x) if (huge + x > 0.0) { /* Raise inexact if x != 0. */ - uint64_t j = i1 + (1LL << (111 - j0)); + uint64_t j = i1 + (1LL << (110 - j0)); if (j < i1) i0 += 1; i1 = j;