-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement the Dragonbox algorithm for Float#to_s
#10913
Implement the Dragonbox algorithm for Float#to_s
#10913
Conversation
spec/std/float_printer_spec.cr
Outdated
pending_win32 "failure case" do | ||
# grisu cannot do this number, so it should fall back to libc | ||
it "grisu failure cases" do | ||
test_pair 4.91e-6, "4.91e-6" | ||
test_pair 3.5844466002796428e+298, "3.5844466002796428e+298" | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since Dragonbox does not depend on LibC
, this ought to pass on Windows too. (If our sprintf
also depends on Dragonbox, then those strings in turn would become platform-independent as well.)
The test suite is now ported over from Microsoft's C++ STL. For simplicity there is a helper method that parses hexadecimal floating-point literals in the form of |
Here is a larger benchmark based on miloyip/dtoa-benchmark. It:
The times shown are the mean times taken to convert one The numbers here should not be compared to those in the linked benchmark directly; they simply dump the result string to a Also bear in mind none of this will affect |
This is a direct Crystal port of jk-jeon/dragonbox@b5b4f65 (with the full cache for
Float64
). It is faster than Grisu3, provides the shortest round-trip guarantee for all inputs, and never depends onLibC.snprintf
; an example where Dragonbox works but Grisu3 fails is4.91e-6
versus4.9099999999999996e-06
. Closes #8441 (according to the paper author Dragonbox is even faster than Ryu).Simple benchmarks:
These benchmarks are not very representative of real string conversion scenarios,
so more comprehensive testing is needed. Also specs.All the existing Grisu3-related modules (except
Float::Printer::IEEE
) are marked as deprecated. They are already:nodoc:
though, sinceFloat::Printer
is. I don't imagine anyone would use those modules directly.