Skip to content

Feat: enforce floating point dot#1407

Open
SGSSGene wants to merge 1 commit intojbeder:masterfrom
SGSSGene:feat/enforce_floating_point_dot
Open

Feat: enforce floating point dot#1407
SGSSGene wants to merge 1 commit intojbeder:masterfrom
SGSSGene:feat/enforce_floating_point_dot

Conversation

@SGSSGene
Copy link
Contributor

This builds on top of PR #1377 adjusting the functionality.

It adds a new Emitter::SetEnforceFloatDot(bool b) function, which allows to enforce that values will have a '.0' append if otherwise no '.' would appear.

Open questions: Is SetEnforceFloatDot a good name? (open to other names).

@romainreignier
Copy link

This looks good for my use-case.
Thanks a lot for having implemented this!

@SGSSGene SGSSGene marked this pull request as draft February 19, 2026 07:27
@SGSSGene SGSSGene marked this pull request as ready for review February 19, 2026 10:25
@SGSSGene
Copy link
Contributor Author

@jbeder this is now ready to go!

* dragonbox only works for floats/doubles not long double
*/
std::string FpToString(long double v, size_t precision) {
std::string FpToString(long double v, bool enforceDot, size_t precision) {
Copy link
Owner

Choose a reason for hiding this comment

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

I would move this choice higher in the stack, leaving this file untouched.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a great suggestion! I wasn't so happy with only adding dots to fixed point representation, but
when something was printed in scientific notation, it suddenly didn't enforce a dot.

Moving it one step up in the stack fixes this. Also I don't have to touch the unit tests of FpToString :-)

void SetStreamablePrecision(std::stringstream&) {}
std::size_t GetFloatPrecision() const;
std::size_t GetDoublePrecision() const;
bool GetEnforceFloatDot() const;
Copy link
Owner

Choose a reason for hiding this comment

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

#namingishard

What about ShowTrailingZero?

Copy link
Contributor Author

@SGSSGene SGSSGene Feb 20, 2026

Choose a reason for hiding this comment

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

Also great suggestion! Before I was worried that "EnforceFloatDot" could be understood as only being applicable for float but not double or long double. This new name is a clear improvement!

@SGSSGene SGSSGene force-pushed the feat/enforce_floating_point_dot branch from 725675e to 9fe3957 Compare February 20, 2026 09:02
…ating point value

This adds a new function Emitter::SetShowTrailingZero(bool).
By setting this, floating point values like '0' or '5' will get an extra
'.0' attached to force others to parse them as floats.

Example:
```
YAML::Emitter emitter;
emitter.SetShowTrailingZero(true);
emitter << ....
```

Fix jbeder#226 jbeder#412 jbeder#1016

Co-Author: Romain Reignier <romain.reignier@exail.com>
@SGSSGene SGSSGene force-pushed the feat/enforce_floating_point_dot branch 2 times, most recently from 12e5d05 to 2b7375e Compare February 20, 2026 09:06
@SGSSGene SGSSGene requested a review from jbeder February 20, 2026 09:08
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.

3 participants

Comments