https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65757
--- Comment #2 from Steve Kargl <sgk at troutmask dot apl.washington.edu> --- 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;