From owner-freebsd-standards Thu Mar 27 12:14:18 2003 Delivered-To: freebsd-standards@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 22FD037B401 for ; Thu, 27 Mar 2003 12:14:16 -0800 (PST) Received: from HAL9000.homeunix.com (12-233-57-131.client.attbi.com [12.233.57.131]) by mx1.FreeBSD.org (Postfix) with ESMTP id 5C06A43F85 for ; Thu, 27 Mar 2003 12:14:15 -0800 (PST) (envelope-from das@FreeBSD.org) Received: from HAL9000.homeunix.com (localhost [127.0.0.1]) by HAL9000.homeunix.com (8.12.6/8.12.5) with ESMTP id h2RKEDah017977 for ; Thu, 27 Mar 2003 12:14:13 -0800 (PST) (envelope-from das@FreeBSD.org) Received: (from das@localhost) by HAL9000.homeunix.com (8.12.6/8.12.5/Submit) id h2RKEDs1017976 for standards@FreeBSD.ORG; Thu, 27 Mar 2003 12:14:13 -0800 (PST) (envelope-from das@FreeBSD.org) Date: Thu, 27 Mar 2003 12:14:13 -0800 From: David Schultz To: standards@FreeBSD.org Subject: printf changes to fix bugs, support long double, etc Message-ID: <20030327201413.GA17165@HAL9000.homeunix.com> Mail-Followup-To: standards@FreeBSD.ORG Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, hits=-7.0 required=5.0 tests=AWL version=2.50 X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) Sender: owner-freebsd-standards@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG 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