This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

printf("%0.0f", 0.5) yields unexpected result (0)



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.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]