-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Feature/dragonbox floats #8883
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
base: master
Are you sure you want to change the base?
Feature/dragonbox floats #8883
Conversation
aardappel
left a comment
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.
Can you put some float formatting tests somewhere? With a wide variety of floats.. then run them both with the old and the new code.
| @@ -0,0 +1,4440 @@ | |||
| // Copyright 2020-2025 Junekey Jeon | |||
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.
This header contains a TON of general float functionality that is not needed for just the task of float 2 string.. I wonder if there is a more minimal version?
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.
I believe we can strip this down all we want -- I just brought in the files wholesale.
include/flatbuffers/util.h
Outdated
| ss << t; | ||
| auto s = ss.str(); | ||
| // Handle NaN | ||
| if (std::isnan(t)) { |
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.
Ok, so how does dragonbox output these? Does it handle them at all? I know its supposed to be fast, but is all this checking potentially slow things down?
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.
The is_decimal function states these are preconditions - if you pass them in you get an assertion failure.
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.
I'll note that the checks probably aren't anywhere near the slowest part of this (or any other part of the code that uses this) -- this code is riddled with std::string allocations :)
include/flatbuffers/util.h
Outdated
| } | ||
|
|
||
| // Handle zero (preserve sign of -0.0 if desired) | ||
| if (t == T{0}) { |
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.
Why does this need a special case?
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.
from the repo readme:
// Here, x should be a nonzero finite number!
// The return value v is a struct with three members:
// significand : decimal significand (1234 in this case);
// it is of type std::uint64_t for double, std::uint32_t for float
// exponent : decimal exponent (-3 in this case); it is of type int
// is_negative : as the name suggests; it is of type bool
auto v = jkj::dragonbox::to_decimal(x);
|
refactored to hide the dragonbox impl and add access to old functions. still need to add tests. |
|
@aardappel added some tests -- if you comment in the line I added to CMakelists.txt you can run the old method. |
|
alright, I got everything but windows happy - it is mad about some type casting that I will have to run down later. |
Fixes #8573