jk-jeon / fp

IEEE-754 binary-to-decimal and decimal-to-binary conversion library
40 stars 5 forks source link

[Question] Question Thread #5

Closed sirinath closed 3 years ago

sirinath commented 3 years ago

How are cache and error numbers generated?

How are the cache numbers (this and this) and error (this) numbers generated?

These numbers are different from what is found in the dragonbox repo.

jk-jeon commented 3 years ago

Yes, the tables in this repo is a strict superset of that in the Dragonbox repo. The reason is because tables in this repo includes additional entries for the reverse (decimal-to-binary) conversion. (The tables in this repo is the union of the entries required for Dragonbox and the entries required for the reverse conversion.)

The source code for the table generation is in this directory: https://github.com/jk-jeon/fp/tree/master/subproject/meta/source.

The code is somewhat non-intuitive, because it involves validity check of cache precision, which is explained in Section 6 of this paper and Section 4 of this paper. It would be very hard to read the code without a fair amount of understanding of the background theory. But I believe it may continue to work also for different formats you probably have in mind with only some minor corrections.

(I closed this because it is more of a question than an issue. Please add follow-up questions in this thread; I will respond to my best.)

sirinath commented 3 years ago

Since there ha been some commits to both dragonbox and fp with fixes, are the 2 repos now consistent with each other?

Also there has hardly been any improvements to either algorithms lately.

jk-jeon commented 3 years ago

The fix in the dragonbox repo should be ported here as well. But I expected to get some feedback on https://github.com/jk-jeon/dragonbox/issues/11#issuecomment-757035179, so I decided to do the patch after updating the code according to the feedback. So far, it seems nobody has been interested in giving some feedback on that...

sirinath commented 3 years ago

Also the implementations of policies in both the repos are complicated. Perhaps it can be simplified to be simple.

sirinath commented 3 years ago

Ideally the 2 repos should be made consistent on merged commits. Additional changes also can be applied when they happen.

jk-jeon commented 3 years ago

Also the implementations of policies in both the repos are complicated. Perhaps it can be simplified to be simple.

Do you have any idea on that?

sirinath commented 3 years ago

At the moment I am not sure. But there is an alternate simplified implementation here: https://github.com/abolz/Drachennest/blob/master/src/dragonbox.cc

I believe in this case the policy options are hard coded.

sirinath commented 3 years ago

Some times it is difficult to track the code when related code appear in many places like: