Web lists-archives.com

Re: [Mingw-users] msvcrt printf bug




Eli, here is the code that I posted earlier in the thread:
http://pastebin.com/z9hYEWF1
And a brief explanation of the algorithm:
https://sourceforge.net/p/mingw/mailman/message/35610100
(don't use that version, it has a bug)
Working backwards, it is possible do convert a decimal string to a binary float using the same 160.160 fixed point intermediary representation.
For the whole part you would get a digit from the left, multiply by 10 then add it in at the unity location; repeat until decimal point.
For the fractional part, you would get the decimal digits from right to left, divide by 10 then add.
This is similar to the float to string, but more complicated, as now we have rounding to consider. We have to chose the closest binary float representation to the decimal string.
I intent to write this in the near future.

--
Securely sent with Tutanota. Claim your encrypted mailbox today!
https://tutanota.com

From: Eli Zaretskii <eliz@gn...> - 2017-02-05 15:45:46
> Date: Sat, 4 Feb 2017 23:40:17 +0100 (CET)
> From: <tei.andu@...>
> 
> Eli, converting a float to string or backwards doesn't have to involve floating point operations.

I don't think conversion is possible without floating-point
operations.  But if you think I'm mistaken, please describe an
algorithm for such conversion that wouldn't use any FP operations.

> I looked at the glibc implementation (printf_fp.c) and it appears to use the GMP library.

GMP is a multiple-precision floating-point library, so it implements
those FP calculations in this case.

> Rounding in the case of truncating significant digits appears to be done on the decimal string.

Even if that's true, you need to produce the decimal string before you
round.  And that requires FP calculations.


 

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