Skip to content

Conversation

@jtdavis777
Copy link
Collaborator

Fixes #8573

@github-actions github-actions bot added c++ codegen Involving generating code from schema labels Dec 24, 2025
Copy link
Collaborator

@aardappel aardappel left a 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
Copy link
Collaborator

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?

Copy link
Collaborator Author

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.

ss << t;
auto s = ss.str();
// Handle NaN
if (std::isnan(t)) {
Copy link
Collaborator

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?

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

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 :)

}

// Handle zero (preserve sign of -0.0 if desired)
if (t == T{0}) {
Copy link
Collaborator

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?

Copy link
Collaborator Author

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);

@jtdavis777 jtdavis777 requested a review from aardappel December 26, 2025 16:19
@jtdavis777
Copy link
Collaborator Author

refactored to hide the dragonbox impl and add access to old functions. still need to add tests.

@jtdavis777
Copy link
Collaborator Author

@aardappel added some tests -- if you comment in the line I added to CMakelists.txt you can run the old method.

@jtdavis777
Copy link
Collaborator Author

alright, I got everything but windows happy - it is mad about some type casting that I will have to run down later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ codegen Involving generating code from schema

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[JSON] Floats do not round-trip

2 participants