Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 27 Mar 2003 12:14:13 -0800
From:      David Schultz <das@FreeBSD.org>
To:        standards@FreeBSD.org
Subject:   printf changes to fix bugs, support long double, etc
Message-ID:  <20030327201413.GA17165@HAL9000.homeunix.com>

next in thread | raw e-mail | index | archive | help
I've reworked the floating point code in printf() with the primary
goal of supporting long double floating point formats.  This had
the side-effect of fixing a number of bugs and adding some
features.  Since the changes are rather extensive, I would
appreciate review of the patches, which are available at:

	http://www.FreeBSD.org/~das/printf.diff

The significant changes are:

- Bugs involving '%F', corner cases of '#' and 'g' format
  specifiers, and the '.*' precision specifier have been
  fixed.

- Some code was redundant, or compensated for dtoa misfeatures
  that have not existed for years.  I have eliminated such cruft
  and tried to clean things up, rely less on implicit state, etc.

- We used to round long double arguments to double.  Now we print
  them properly.  (I can trivially #ifdef WANT_LONG_DOUBLE the long
  double support if people want that, but I'm guessing the #ifdef
  FLOATING_POINT will be sufficient for embedded systems and such.)

- Added support for the "'" specifier to print thousands' grouping
  characters in a locale-dependent manner.  This was easy to add,
  but the logic is a little complicated.  It would be great if
  people who use a locale with grouping characters could test.

- Some buffer sizes have been updated.  In particular, the buffer in
  exponent() should be ~5 characters wide instead of 308.  The 'buf'
  array in printf() is no longer used for floating point, so it
  only needs to be big enough to hold integer digits (40 bytes
  instead of 656.)  The sizes should really be MD, but I
  overestimated instead.  If this bothers anyone, I'm open to
  suggestions.

- I have not implemented hexadecimal floating point (%[aA]), since
  I think someone else is working on that, but I have set things up
  nicely to facilitate that.  Converting to hex will be easy since
  no rounding is needed; the mantissa can be processed one nibble at
  a time.  Once that is done, our printf() should be C99-compliant.

I will be out of town until Sunday or Monday, and I may not be
able to respond to any comments until I return.


P.S.	I have not yet touched *fwprintf() beyond what was necessary
	to make the code it continue to compile.  The changes to it
	will essentially mirror the changes to printf(), although the
	buffer sizes may merit special consideration.

P.P.S.	Long doubles on sparc64 don't work yet due to a minor bug.
	Namely, gdtoa() expects the array of bits you pass it
	containing the mantissa to have an explicit leading 1 if
	the number of normalized.  I just need a small MD fix, which
	I will get to when I return.

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-standards" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030327201413.GA17165>