Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe@cygwin.com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-help@cygwin.com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
Delivered-To: mailing list cygwin@cygwin.com
Date: Thu, 30 Jun 2005 14:45:37 +0200 (CEST)
Message-ID: <3600032.1120135537858.JavaMail.adm-moff@moffice2.nsc.no>
From: "Peter J. Acklam" <pjacklam@online.no>
To: <cygwin@cygwin.com>
Subject: SV: SV: Bug in printf ?
Cc: <pjacklam@online.no>
In-Reply-To: <SERRANO8kxpycYGQ74C000002d5@SERRANO.CAM.ARTIMI.COM>
Mime-Version: 1.0
Content-Type: multipart/mixed;  	boundary="----=_Part_8661_15704335.1120135537836"
References: <6879888.1120133556579.JavaMail.adm-moff@moffice2.nsc.no>   <SERRANO8kxpycYGQ74C000002d5@SERRANO.CAM.ARTIMI.COM>
X-IsSubscribed: yes

------=_Part_8661_15704335.1120135537836
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 7bit

Dave Korn wrote:

> Have you considered that your sunblade might be operating
> in a different rounding mode, by default?

I didn't know there were different rounding modes.
I thought everyone used so-called "unbiased rounding",
so I'm sorry for adding confusion.

> I would imagine that printf may well work under-the-hood
> by shifting the desired decimal places above the point,
> rounding to integer, and printing out that number.

Could be.  I haven't dug into those matters, but your
suggestion certainly makes sense.

Anyway, the following line

   seq -4.5 1 4.5 | while read x; do printf '%4s -> %3.0f\n' $x $x; done

which gives

   -4.5 ->  -4
   -3.5 ->  -3
   -2.5 ->  -2
   -1.5 ->  -1
   -0.5 ->  -1
    0.5 ->   1
    1.5 ->   1
    2.5 ->   2
    3.5 ->   3
    4.5 ->   4

suggests that printf rounds towards zero, but something
funny happens for -0.5 and 0.5.

Peter


------=_Part_8661_15704335.1120135537836
Content-Type: text/plain; charset=us-ascii

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/
------=_Part_8661_15704335.1120135537836--

