Test code:
    long double x = __builtin_infl();
    int main() {
        int r = x == __builtin_infl();
        return r ? 0 : 1;
    }

Commands to reproduce:

    gcc -mlong-double-128 tc.c
    ./a.out && echo ok || echo fail

No problem with -mlong-double-64.

Cause:

GCC first transforms (x == infinity) to (x > long_double_max_val).
The maximum value returned by real_maxval is encoded as infinity due
to rounding in encode_ibm_extended.  This does not happen with the
LDBL_MAX declared in system headers because one of the bits is
cleared.

Potential fix:

--- real.c.orig 2005-09-19 12:56:24.000000000 -0400
+++ real.c      2006-04-25 21:18:32.000000000 -0400
@@ -2205,6 +2205,8 @@ real_maxval (REAL_VALUE_TYPE *r, int sig
   np2 = SIGNIFICAND_BITS - fmt->p * fmt->log2_b;
   memset (r->sig, -1, SIGSZ * sizeof (unsigned long));
   clear_significand_below (r, np2);
+  if (REAL_MODE_FORMAT_COMPOSITE_P (mode))
+      clear_significand_bit (r, SIGNIFICAND_BITS - fmt->pnan - 1);
 }


-- 
           Summary: Compare against constant infinity fails with IBM long
                    double format
           Product: gcc
           Version: 4.0.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: dvdfrdmn at users dot sf dot net
GCC target triplet: powerpc-apple-darwin8


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27321

Reply via email to