Web lists-archives.com

Re: [Mingw-users] msvcrt printf bug

On 1/16/2017 4:36 PM, tei.andu@xxxxxxxxxxxx wrote:
> [snip snip snip]
> KHMan: I think you are wrong here. Every valid floating point
> representation that is not NaN or inf
> corresponds to an exact, non recurring fraction representation in
> decimal. There is no reason why
> printf shouldn't print that exact representation when needed, as
> the glibc printf does.
> For instance:
> 0x5D5F27A3: 14624675 * 2^(59 - 23) = 1005000013434060800 this
> prints correctly with msvcrt printf
> 0x5D5F27A4: 14624676 * 2^(59 - 23) = 1005000082153537536 this
> prints wrong with msvcrt printf for me: 1005000082153537500.
> Larger values also print slightly off.
> We are talking about whole numbers here, fractional part is zero.
> An acceptable loss in precision occurs when converting from a
> decimal representation to a float number due to limited precision
> in float:
> 0.1 is closest represented by 0x3DCCCCCD, which is exactly:
> 13421773 * 2^(-4 - 23) = 0.100000001490116119384765625
> 3e20 is closest represented by 0x61821AB1, which is exactly:
> 8526513 * 2^(68 - 23) = 300000006012263202816. We get 7 valid
> digits, this is normal and acceptable.
> Also the fact that the float number is converted to double doesn't
> matter, double can hold every possible float without loss in
> precision.
> I also tried the printf in the old crtdll.dll, same behavior.

Oh, I should never have promised not to post again, heh.

The double precision number after conversion is the same. I 
verified this on MinGW 5.3.0 and Linux Mint 17 (gcc 4.8). Try it 
out yourself.

If you don't understand why none of us cared that printf printed 
something slightly different, then your programming education has, 
in fact, lacked something.

Kein-Hong Man (esq.)
Selangor, Malaysia

Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
MinGW-users mailing list

This list observes the Etiquette found at 
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

You may change your MinGW Account Options or unsubscribe at:
Also: mailto:mingw-users-request@xxxxxxxxxxxxxxxxxxxxx?subject=unsubscribe