From owner-freebsd-standards@FreeBSD.ORG Sun Sep 5 19:56:54 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 16E2016A4CE for ; Sun, 5 Sep 2004 19:56:54 +0000 (GMT) Received: from bgezal.rise.tuwien.ac.at (bgezal.rise.tuwien.ac.at [128.130.59.74]) by mx1.FreeBSD.org (Postfix) with ESMTP id 9ABD743D53 for ; Sun, 5 Sep 2004 19:56:49 +0000 (GMT) (envelope-from stefan@fafoe.narf.at) Received: from fafoe.narf.at (unknown [212.186.3.235]) by bgezal.rise.tuwien.ac.at (Postfix) with ESMTP id A803620A2; Sun, 5 Sep 2004 21:56:47 +0200 (CEST) Received: from wombat.fafoe.narf.at (wombat.fafoe.narf.at [192.168.1.42]) by fafoe.narf.at (Postfix) with ESMTP id 62F9740EE; Sun, 5 Sep 2004 21:56:41 +0200 (CEST) Received: by wombat.fafoe.narf.at (Postfix, from userid 1001) id 165ECDC; Sun, 5 Sep 2004 21:56:38 +0200 (CEST) Date: Sun, 5 Sep 2004 21:56:38 +0200 From: Stefan Farfeleder To: Steve Kargl Message-ID: <20040905195632.GG72545@wombat.fafoe.narf.at> 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=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit 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:56:54 -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. The output is correct: e, E A double argument representing a floating-point number is converted in the style [-]d.ddd eħdd, where there is one digit (which is nonzero if the argument is nonzero) before the decimal-point character and the number of digits after it is equal to the precision; if the precision is missing, it is taken as 6; if the precision is zero and the # flag is not specified, no decimal-point character appears. The value is rounded to the appropriate number of digits. [...] Cheers, Stefan