Feature: Make U256::to_f64_lossy more accurate #726
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Based off of this blog post: https://blog.m-ou.se/floats/ (I tried to get the gist of this into the comments, but it's kind of long.)
This method of converting large unsigned integers into f64 is more accurate, but from my rough benchmarks, for most numbers there's at least a 3x slow down, and for some numbers (that work well with the simple method currently used) it's as much as a 10x slow down for speed.
Sacrificing speed for accuracy.
Please close if this is a trade off that's not acceptable.
I'd assume anyone dealing with floats is not expecting accuracy, but at the same time, I'm not too sure exactly how the current method's inaccuracies will manifest themselves.
Anywho, I was doing this work for another PR and thought it might be useful here.