This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
printf("%0.0f", 0.5) yields unexpected result (0)
- To: "'gcc-bugs at gcc dot gnu dot org'" <gcc-bugs at gcc dot gnu dot org>
- Subject: printf("%0.0f", 0.5) yields unexpected result (0)
- From: Marc Boeren <M dot Boeren at guidance dot nl>
- Date: Thu, 17 Aug 2000 12:28:36 +0200
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.
Cheerio, Marc.