Decimal floating point to binary floating point
12-25-2018, 11:37 PM
Post: #3
 Albert Chan Senior Member Posts: 2,494 Joined: Jul 2018
RE: Decimal floating point to binary floating point
(12-25-2018 08:32 AM)Thomas Klemm Wrote:  ... in case of 8.25e84 we'd end up with:

8.25 * 1e4 * 1e16 * 1e64

Sun code actually do this: 8.25e84 => 825e82 => 825 * 1e2 * 1e16 * 1e64

By starting the mantissa as integer, it can do fast-path trick, say 1.23e-12 => 123 / 1e14
Hardware divide (assuming FE_PC53_ENV and FE_TONEAREST) guaranteed correct conversion.

Above binary conversion is correct, but it is just lucky.
It is possible multiplied result are off, 1 ULP or more.

The slow and messy part is the correction loop, to fix the approximated binary float.

This is my implementation, using normalized 96-bits big float: strtod-fast.c

I also made a lite version that does not use arbitrary precision math to break ties.
The cost is a very slight chance of wrong conversion, ± 1 ULP

https://github.com/achan001/dtoa-fast
 « Next Oldest | Next Newest »

 Messages In This Thread Decimal floating point to binary floating point - Dan - 12-25-2018, 04:06 AM RE: Decimal floating point to binary floating point - Thomas Klemm - 12-25-2018, 08:32 AM RE: Decimal floating point to binary floating point - Albert Chan - 12-25-2018 11:37 PM RE: Decimal floating point to binary floating point - Dan - 12-26-2018, 07:10 AM RE: Decimal floating point to binary floating point - Paul Dale - 12-26-2018, 07:51 AM RE: Decimal floating point to binary floating point - Dan - 01-03-2019, 06:53 AM RE: Decimal floating point to binary floating point - Dan - 12-26-2018, 08:46 AM RE: Decimal floating point to binary floating point - BruceH - 12-30-2018, 05:46 PM RE: Decimal floating point to binary floating point - SlideRule - 12-30-2018, 11:36 PM RE: Decimal floating point to binary floating point - Thomas Klemm - 12-26-2018, 11:14 AM RE: Decimal floating point to binary floating point - Dan - 12-28-2018, 03:45 AM RE: Decimal floating point to binary floating point - Paul Dale - 12-28-2018, 09:33 AM RE: Decimal floating point to binary floating point - Dan - 01-01-2019, 07:27 AM

User(s) browsing this thread: 1 Guest(s)