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

--- Comment #8 from Jerry DeLisle <jvdelisle at gcc dot gnu.org> ---
I have had to explore this a bit to get to a point of understanding. The
following C example shows building the HEX float strings and the incantations
needed. For those systems that support the 17 byte float format, I have not
found what is needed yet.

#include <stdio.h>
#include <quadmath.h>

int main()
{
  char buf[128];
  float x =       1.0f / 3.0f;
  double y =      1.0l / 3.0l;
  long double z = 1.0L / 3.0L;
  __float128 q = 1.0Q / 3.0Q;
  printf("   FLOAT: %.7A\n", x);
  printf("  DOUBLE: %.15lA\n", y);
  printf("LONG DBL: %.18LA\n", z);

  int n = quadmath_snprintf (buf, sizeof buf, "%.30QA", q);
  if ((size_t) n < sizeof buf)
  printf ("QUAD DBL: %s\n", buf);

  printf("              1234567890123456789012345678901234567890\n");
  printf("   FLOAT:   %.9f\n", x);
  printf("  DOUBLE:   %.18lf\n", y);
  printf("LONG DBL:   %.22Lf\n", z);
  printf("QUAD DBL:   %.36Qf \n", q);
}

I still need to look at the code for the kind 17 and where to test it.

$ gcc hexfloat.c -lquadmath
$ ./a.out 
   FLOAT: 0X1.5555560P-2
  DOUBLE: 0X1.555555555555500P-2
LONG DBL: 0XA.AAAAAAAAAAAAAAB000P-5
QUAD DBL: 0X1.555555555555555555555555555500P-2
              1234567890123456789012345678901234567890
   FLOAT:   0.333333343
  DOUBLE:   0.333333333333333315
LONG DBL:   0.3333333333333333333424
QUAD DBL:   0.333333333333333333333333333333333317

Reply via email to