Subject: PR 18803 - printf(3) does not handle long double
To: None <tech-userlevel@netbsd.org>
From: Jesper Louis Andersen <jlouis@mongers.org>
List: tech-userlevel
Date: 01/12/2005 18:59:07
I think it should ;)

Full PR is at

http://www.netbsd.org/cgi-bin/query-pr-single.pl?number=18803

After reading that, one should also read 

http://www.netbsd.org/cgi-bin/query-pr-single.pl?number=14168

which is dependent on the first. The good thing here is thaht i
thought I should fight the hard game and implement isinf() 
and isnan() for long doubles, but I might get the easy ticket
out there.

I had begun compiling a list of sizeof(long double) as well as the
exponent/mantissa/sign division of individual architectures, but
this now seems to be irrelevant, as 14168 states we have support.

And we have:

/* $Id: skeleton.c,v 1.1 2003/03/27 18:24:06 jlouis Exp $
 * 
 * Jesper Louis Andersen
 */

#include <limits.h>
#include <math.h>
#include <x86/float.h>

int
main()
{
  long double m  = __LDBL_MAX__;
  long double mm = m * 2;

  if (isinf(m)) 
    printf ("1\n");
  else 
    printf ("2\n");

  if (isinf(mm))
    printf ("3\n");
  else
    printf ("4\n");


  return 0;
}

returns
2
3

as expected.
Anyway, here is the plan:

If we are going to format a LDBL, we copy it into a work-area and
check it for Inf and NAN. If this goes through, we do the usual
conversion of it, by altering the conversion routines there is now.

What I am not sure about is the performance issue. Throwing everything
into a long double (included floats and doubles) might be overkill, 
but it is the simplemest solution. If that is not an option, I need
somewhat seperate code paths for the long double case compared to the
double case (which includes the float case). 

Conversion done, we clean up, and push the formatted double to the
fd.

-- 
jlouis