From owner-freebsd-standards@FreeBSD.ORG Sun Sep 5 19:51:56 2004 Return-Path: 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 1E25016A4CE for ; Sun, 5 Sep 2004 19:51:56 +0000 (GMT) Received: from av15-1-sn4.m-sp.skanova.net (av15-1-sn4.m-sp.skanova.net [81.228.10.102]) by mx1.FreeBSD.org (Postfix) with ESMTP id 22B3B43D31 for ; Sun, 5 Sep 2004 19:51:55 +0000 (GMT) (envelope-from ertr1013@student.uu.se) Received: by av15-1-sn4.m-sp.skanova.net (Postfix, from userid 502) id F0E0B37E49; Sun, 5 Sep 2004 21:51:53 +0200 (CEST) Received: from smtp4-2-sn4.m-sp.skanova.net (smtp4-2-sn4.m-sp.skanova.net [81.228.10.180]) by av15-1-sn4.m-sp.skanova.net (Postfix) with ESMTP id DBDD237E42 for ; Sun, 5 Sep 2004 21:51:53 +0200 (CEST) Received: from falcon.midgard.homeip.net (h201n1fls24o1048.bredband.comhem.se [212.181.162.201]) by smtp4-2-sn4.m-sp.skanova.net (Postfix) with SMTP id AC1C437E45 for ; Sun, 5 Sep 2004 21:51:53 +0200 (CEST) Received: (qmail 9236 invoked by uid 1001); 5 Sep 2004 19:51:53 -0000 Date: Sun, 5 Sep 2004 21:51:52 +0200 From: Erik Trulsson To: Steve Kargl Message-ID: <20040905195152.GA6096@falcon.midgard.homeip.net> Mail-Followup-To: Steve Kargl , freebsd-standards@freebsd.org References: <20040905193640.GA37190@troutmask.apl.washington.edu> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20040905193640.GA37190@troutmask.apl.washington.edu> User-Agent: Mutt/1.5.6i cc: freebsd-standards@freebsd.org Subject: Re: is printf() broken? X-BeenThere: freebsd-standards@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Standards compliance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 05 Sep 2004 19:51:56 -0000 On Sun, Sep 05, 2004 at 12:36:40PM -0700, Steve Kargl wrote: > The following program > > #include > int main(void) { > int d; > double x; > x = 1.234E05; > for (d = 0; d < 5; d++) > printf("%+-31.*e\n", d, x); > return 0; > } > > generates > > +1e+05 > +1.2e+05 > +1.23e+05 > +1.234e+05 > +1.2340e+05 > > The question is whether the first number should be > "+1.e+05". That is, is the printing of the decimal > point required or optional? I only have Harbison > and Steele's book and it does not state what the > expected behavior should be. I believe printf() is correct, and that the printing of the decimal point for the first number above is neither required nor optional but actually not allowed at all >From Harbison & Steele 5th edition: The e and E conversions [...] If the precision is 0, then no digits appear after the decimal point. Moreover the decimal point also does not appear unless the # flag is present. (Nearly identical text is also in H&S 3rd edition.) >From n869.txt (the last publically available draft of C99) [the e and E conversions for fprintf] [...] if the precision is zero and the # flag is not specified, no decimal-point character appears -- Erik Trulsson ertr1013@student.uu.se