https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78214

            Bug ID: 78214
           Summary: nanq() does not return a quiet NaN
           Product: gcc
           Version: 5.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libquadmath
          Assignee: unassigned at gcc dot gnu.org
          Reporter: levim at php dot net
  Target Milestone: ---

Created attachment 39967
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=39967&action=edit
Potential patch for the fix.

I compiled the following program, loaded it up in GDB and did a hex dump on the
nan:

    #include <quadmath.h>
    int main(void) {
        __float128 nan = nanq(NULL);
        return 0;
    }

The result looked like this:

    0x7fffffffde40:     0x00    0x00    0x00    0x00    0x00    0x00    0x00   
0x00
    0x7fffffffde48:     0x01    0x00    0x00    0x00    0x00    0x00    0xff   
0x7f

I have only recently started learning about NaN encodings so I may be wrong,
but I do believe that the above NaN is signalling, but the documentation for
`nanq` says it will return a quiet NaN. Shouldn't a quiet NaN look like this?

    0x7fffffffde40:     0x00    0x00    0x00    0x00    0x00    0x00    0x00   
0x00
    0x7fffffffde48:     0x00    0x00    0x00    0x00    0x00    0x80    0xff   
0x7f

It's easy to see from the source why it is this way:

    #include "quadmath-imp.h"

    __float128
    nanq (const char *tagp __attribute__ ((unused)))
    {
      // FIXME -- we should use the argument
      ieee854_float128 f;
      f.ieee.exponent = 0x7fff;
      f.ieee.mant_high = 0x1;
      return f.value;
    }

The mant_high is set to 0x1 instead of something like 0x800000000000 (I think I
got the correct number of zeros there, anyway).

Reply via email to