AK: Add an exact and fast floating point parsing algorithm · SerenityOS/serenity@53b7f5e (original) (raw)
Navigation Menu
- GitHub Copilot Write better code with AI
- GitHub Models New Manage and compare prompts
- GitHub Advanced Security Find and fix vulnerabilities
- Actions Automate any workflow
- Codespaces Instant dev environments
- Issues Plan and track work
- Code Review Manage code changes
- Discussions Collaborate outside of code
- Code Search Find more, search less
- Explore
- Pricing
Provide feedback
Saved searches
Use saved searches to filter your results more quickly
Appearance settings
Commit 53b7f5e
authored and
committed
AK: Add an exact and fast floating point parsing algorithm
This is based on the paper by Daniel Lemire called "Number parsing at a Gigabyte per second", currently available athttps://arxiv.org/abs/2101.11408An implementation can be found athttps://github.com/fastfloat/fast_floatTo support both strtod like methods and String::to_double we have two different APIs. The parse_first_floating_point gives back both the result, next character to read and the error/out of range status. Out of range here means we rounded to infinity 0. The other API, parse_floating_point_completely, will return a floating point only if the given character range contains just the floating point and nothing else. This can be much faster as we can skip actually computing the value if we notice we did not parse the whole range. Both of these APIs support a very lenient format to be usable in as many places as possible. Also it does not check for "named" values like "nan", "inf", "NAN" etc. Because this can be different for every usage. For integers and small values this new method is not faster and often even a tiny bit slower than the current strtod implementation. However the strtod implementation is wrong for a lot of values and has a much less predictable running time. For correctness this method was tested against known string -> double datasets from https://github.com/nigeltao/parse-number-fxx-test-dataThis method gives 100% accuracy. The old strtod gave an incorrect value in over 50% of the numbers tested.
File tree
5 files changed
lines changed
5 files changed
lines changed
Lines changed: 1 addition & 0 deletions
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
1 | 1 | set(AK_SOURCES |
2 | 2 | Assertions.cpp |
3 | 3 | Base64.cpp |
4 | +FloatingPointStringConversions.cpp | |
4 | 5 | FlyString.cpp |
5 | 6 | Format.cpp |
6 | 7 | FuzzyMatch.cpp |