Skip to content

fix: prettier floating point numbers#1293

Merged
jbeder merged 12 commits into
jbeder:masterfrom
SGSSGene:fix/ugly_floats
Nov 7, 2024
Merged

fix: prettier floating point numbers#1293
jbeder merged 12 commits into
jbeder:masterfrom
SGSSGene:fix/ugly_floats

Conversation

@SGSSGene

@SGSSGene SGSSGene commented Jul 6, 2024

Copy link
Copy Markdown
Collaborator

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

jbeder commented Jul 7, 2024

Copy link
Copy Markdown
Owner

@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
Copy Markdown
Collaborator 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

jk-jeon commented Jul 15, 2024

Copy link
Copy Markdown

@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
Copy Markdown

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?

Comment thread include/yaml-cpp/fp_to_string.h Outdated
Comment thread include/yaml-cpp/fp_to_string.h Outdated
@SGSSGene

Copy link
Copy Markdown
Collaborator 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
Copy Markdown
Collaborator 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
Copy Markdown
Collaborator 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

jbeder commented Jul 30, 2024

Copy link
Copy Markdown
Owner

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
Copy Markdown
Collaborator 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

Anton3 commented Aug 27, 2024

Copy link
Copy Markdown

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

@SGSSGene

Copy link
Copy Markdown
Collaborator Author

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

@SGSSGene

Copy link
Copy Markdown
Collaborator Author

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

@davidzchen

davidzchen commented Sep 29, 2024

Copy link
Copy Markdown

Sorry for the delay. Changes LGTM on my side.

@jbeder Can you please take a look at this?

@davidzchen

Copy link
Copy Markdown

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

@SGSSGene

Copy link
Copy Markdown
Collaborator Author

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

@jbeder jbeder left a comment

Copy link
Copy Markdown
Owner

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?

Comment thread include/yaml-cpp/fptostring.h Outdated
Comment thread src/fptostring.cpp Outdated
Comment thread src/fptostring.cpp
@jk-jeon

jk-jeon commented Oct 21, 2024

Copy link
Copy Markdown

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.

Comment thread src/fptostring.cpp
@SGSSGene SGSSGene requested a review from jbeder October 22, 2024 18:53
@SGSSGene

SGSSGene commented Nov 7, 2024

Copy link
Copy Markdown
Collaborator Author

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

@jbeder jbeder merged commit 9ce5a25 into jbeder:master Nov 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Floating-point numbers are uglified, a.k.a. write shortest floating-point representation with round-trip guarantee

5 participants