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]

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


>>>>> 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

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