Skip to content
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

fix: prettier floating point numbers #1293

Merged
merged 12 commits into from
Nov 7, 2024
Merged

Conversation

SGSSGene
Copy link
Contributor

@SGSSGene SGSSGene commented Jul 6, 2024

fixes #1289.

This PR adds a new function fp_to_string.
fp_to_string internally uses dragonbox to compute the required precision to print floating point numbers. This avoids uglification of floating point numbers that happen by default via std::stringstream.

Numbers like 34.34 will be converted to '34.340000000000003' as strings. With this version they will be converted to the string '34.34'.

  • adjust dragonbox.h so everything is wrapped in a YAML namespace
  • discuss possible license adjustments for dragonbox.h
  • move dragonbox.h to contrib
  • requires OK of licensing from jk-jeon
  • make sure this solves the issue.

@jbeder
Copy link
Owner

jbeder commented Jul 7, 2024

@jk-jeon, given your expertise, would you be willing to review this?

@SGSSGene SGSSGene force-pushed the fix/ugly_floats branch 7 times, most recently from 8a3c7b3 to b81ffd7 Compare July 14, 2024 21:35
@SGSSGene
Copy link
Contributor Author

@Anton3: Could you check that this PR is actually solving your issue?

@jk-jeon: Can you check if the license in changes in a include/yaml-cpp/contrib/dragonbox.h to your liking? (I have tripled licensed them).

I belive this PR is ready to go.

@SGSSGene SGSSGene changed the title [NOMERGE] fix: prettier floating point numbers fix: prettier floating point numbers Jul 14, 2024
@jk-jeon
Copy link

jk-jeon commented Jul 15, 2024

@jk-jeon: Can you check if the license in changes in a include/yaml-cpp/contrib/dragonbox.h to your liking? (I have tripled licensed them).

Looks good. Thanks!

@davidzchen
Copy link

It looks like the indentation style of the new code is inconsistent with that of the rest of the codebase (4 vs 2 spaces). @SGSSGene can you make the style consistent?

@SGSSGene
Copy link
Contributor Author

It looks like the indentation style of the new code is inconsistent with that of the rest of the codebase (4 vs 2 spaces). @SGSSGene can you make the style consistent?

Yes, very good points.

Should I also make a fp_to_string.cpp file? Most things don't really have to be in the header file.

@SGSSGene SGSSGene force-pushed the fix/ugly_floats branch 2 times, most recently from dda0397 to 1fe5866 Compare July 18, 2024 17:44
@SGSSGene SGSSGene requested a review from davidzchen July 22, 2024 08:25
@SGSSGene SGSSGene force-pushed the fix/ugly_floats branch 2 times, most recently from 4ccb3a6 to acf2e70 Compare July 30, 2024 09:53
@SGSSGene
Copy link
Contributor Author

It looks like the indentation style of the new code is inconsistent with that of the rest of the codebase (4 vs 2 spaces). @SGSSGene can you make the style consistent?

Yes, very good points.

Should I also make a fp_to_string.cpp file? Most things don't really have to be in the header file.

I split fp_to_string.h into src/fptostring.cpp and include/yaml-cpp/fptostring.h. This also allowed to move dragonbox.h into src/contrib folder.

@SGSSGene
Copy link
Contributor Author

@jbeder an you help me out with the current windows-shared-build errors? (I currently don't have a windows machine at hand). I thought adding YAML_CPP_API in fptostring.h would be enough. But it seems like the symbols are not being exported into the DLL?

@jbeder
Copy link
Owner

jbeder commented Jul 30, 2024

Honestly I don't know, I don't have a Windows machine any more either :)

Maybe ask on Stack Overflow? I'd be shooting in the dark also.

@SGSSGene SGSSGene force-pushed the fix/ugly_floats branch 2 times, most recently from f40095f to f4368b1 Compare July 30, 2024 18:37
@SGSSGene
Copy link
Contributor Author

Honestly I don't know, I don't have a Windows machine any more either :)

Maybe ask on Stack Overflow? I'd be shooting in the dark also.

Found the issue: the fptostring.cpp didn't include fptostring.h, which than didnt see the "YAML_CPP_API" declaration, which then didn't export the symbols into the dll. Fixed now!

Ready to go from my side :-)

@Anton3
Copy link

Anton3 commented Aug 27, 2024

@jbeder Could you give another round of review, please? Can't wait to stop uglifying my configs :)

@SGSSGene
Copy link
Contributor Author

Hi @jbeder , any chance you can take another look?

@SGSSGene
Copy link
Contributor Author

Hey @jbeder, a polite reminder that this is still open :-)

@davidzchen
Copy link

davidzchen commented Sep 29, 2024

Sorry for the delay. Changes LGTM on my side.

@jbeder Can you please take a look at this?

@davidzchen
Copy link

@jbeder Are there any other blockers before this can be merged?

@SGSSGene
Copy link
Contributor Author

@jbeder, any thing we can do, to motivate you looking at this PR?

Copy link
Owner

@jbeder jbeder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I've been busy. Also, has the owner of dragonbox approved this PR?

include/yaml-cpp/fptostring.h Outdated Show resolved Hide resolved
src/fptostring.cpp Outdated Show resolved Hide resolved
src/fptostring.cpp Show resolved Hide resolved
@jk-jeon
Copy link

jk-jeon commented Oct 21, 2024

Also, has the owner of dragonbox approved this PR?

I approved the license notification.
If you are talking about the implementation itself, I still think precision specification is fundamentally incompatible with the shortest roundtripping representation and don't recommend mixing them together, but if 100% correct rounding/roundtrip is not your goal than it seems okay.

src/fptostring.cpp Show resolved Hide resolved
@SGSSGene SGSSGene requested a review from jbeder October 22, 2024 18:53
@SGSSGene
Copy link
Contributor Author

SGSSGene commented Nov 7, 2024

@jbeder Hey jbeder, friendly reminder, I made the adjustments you suggested to make.

@jbeder jbeder merged commit 9ce5a25 into jbeder:master Nov 7, 2024
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants