Web lists-archives.com

Re: [Mingw-users] msvcrt printf bug




On 16/01/17 08:36, tei.andu@xxxxxxxxxxxx wrote:
> ...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.

Sorry, I have followed this thread loosely but I am struggling to see 
the practical relevance of this.

It is normal to perform floating-point operations using a couple of 
extra digits (so-called guard digits) to boost accuracy. In my 
experience, 80x87 co-processors often generate internal precisions of 
19-20 digits. But if the number is stored back to an 8-byte memory slot, 
it will perforce be rounded down to 15-16 digits.  In practice, most 
meaningful floating point calculations will use standard memory slots to 
save intermediate values. Therefore you should not believe anything 
beyond 15-16 digits.  In light of this, I suspect somebody at Microsoft 
has made the, arguably sensible, engineering decision not to fuss too 
much about correctly handling the 18th and 19th digits. In practice, 
these digits will usually be garbage!

Bottom line: Double-precision IEEE floating-point arithmetic is only 
specified to be reliable up to 15-16 digits. You should not bet the farm 
on the values of any 18th or 19th digits printf may produce. Ultimately, 
at some level, floating point arithmetic is only ever approximate!

P.

>
> ...snip
>


------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi
_______________________________________________
MinGW-users mailing list
MinGW-users@xxxxxxxxxxxxxxxxxxxxx

This list observes the Etiquette found at 
http://www.mingw.org/Mailing_Lists.
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:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:mingw-users-request@xxxxxxxxxxxxxxxxxxxxx?subject=unsubscribe