I noticed slightly different floating point results with Pelles C compared to other C compilers. I tracked it down to how certain decimal values are rounded when converted to the IEEE double precision binary format (sign:1 bit, exponent:11 bits, mantissa:52 bits)

Most values are rounded properly. For example, 0.9 is stored as 0x3feccccccccccccd. The final hex digit is correctly rounded up to d since c>8.

However, the value 0.3 is stored as 0x3fd3333333333334. Notice the final hex digit is rounded up to 4 but it seems like it should be rounded down to 3 since 3<8. I thought perhaps a "round to even" rule might be in use, but this doesn't seem to be the case as it sometimes unexpectedly rounds up to even and other times it rounds up to odd.

Also, with values that are powers of 2 larger, the rounding is inconsistent.

0.6 = 0x3fe3333333333334 ?

1.2 = 0x3ff3333333333333

5.6 = 0x4016666666666667 ?

11.2 = 0x4026666666666666

0.72 = 0x3fe70a3d70a3d70b ?

1.44 = 0x3ff70a3d70a3d70a

0.84 = 0x3feae147ae147ae2 ?

1.68 = 0x3ffae147ae147ae1

This happens at compile time (x=0.3) as well as at run time with atof() and scanf() functions. I have not come across any such unusual rounding for single precision floats, just doubles.

I checked with 6 other compilers (ms, gcc, clang, intel, watcom, digital mars) and they all round to the nearest digit in these cases rather than rounding up.

Is this a bug? or simply a rounding scheme with which I am not familiar?