This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: printf("%0.0f", 0.5) yields unexpected result (0)
- To: Marc Boeren <M dot Boeren at guidance dot nl>
- Subject: Re: printf("%0.0f", 0.5) yields unexpected result (0)
- From: Andreas Jaeger <aj at suse dot de>
- Date: 17 Aug 2000 13:49:00 +0200
- Cc: "'gcc-bugs at gcc dot gnu dot org'" <gcc-bugs at gcc dot gnu dot org>
- References: <7BE0F4A5D7AED2119B7500A0C94C58AC094A8F@DELLSERVER>
>>>>> Marc Boeren writes:
> Hi,
> I noticed the following behaviour using printf:
> printf("%0.0f", 0.5); // prints 0
> printf("%0.0f", 1.5); // prints 2
> printf("%0.0f", 2.5); // prints 2
> printf("%0.0f", 3.5); // prints 4
> where I would have expected 1, 2, 3 and 4, respectively.
> It is easily reproduced by the sh-utils printf as well.
> Now I know that .5 is a bordercase (as is .05 when trying %0.1f, which also
> yields unexpected results), but still...
> This happened with
> gcc version 2.95.2 19991023 (release-2) // as part of a CygWin
> installation on WinNT4
> and
> gcc version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release) // as part of
> a RedHat 6.1 default installation.
ISO C demands that we round to even, this is correct behaviour.
Andreas
--
Andreas Jaeger
SuSE Labs aj@suse.de
private aj@arthur.inka.de
http://www.suse.de/~aj