Post Reply 
Decimal floating point to binary floating point
12-25-2018, 11:37 PM
Post: #3
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
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Decimal floating point to binary floating point - Albert Chan - 12-25-2018 11:37 PM



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