[Bug libquadmath/78214] New: nanq() does not return a quiet NaN

2016-11-04 Thread levim at php dot net
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 
int main(void) {
__float128 nan = nanq(NULL);
return 0;
}

The result looked like this:

0x7fffde40: 0x000x000x000x000x000x000x00   
0x00
0x7fffde48: 0x010x000x000x000x000x000xff   
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?

0x7fffde40: 0x000x000x000x000x000x000x00   
0x00
0x7fffde48: 0x000x000x000x000x000x800xff   
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 0x8000 (I think I
got the correct number of zeros there, anyway).

[Bug libquadmath/78214] nanq() does not return a quiet NaN

2016-11-04 Thread levim at php dot net
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78214

--- Comment #1 from Levi Morrison  ---
Perhaps a less error-prone way to set that same bit is:

UINT64_C(0x1) << 47

Not sure what would be preferred.