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

User-defined double output precision #15

Closed
wants to merge 3 commits into from

Conversation

pah
Copy link
Contributor

@pah pah commented Jun 25, 2014

Writing a double to an OutputStream current prints at most 6 significant
digits (according to the C standard).

The functions Set/GetDoublePrecision(), added to the Writer classes
can be used to fluently set the precision, i.e. the number of significant
digits to use for writing the double:

  Writer<...> writer(...);
  d.Accept(writer.SetDoublePrecision(12)); // print up to 12 significant digits

Additionally, a new Double(double,int) overload is added to the Writer classes,
allowing to programmatically write a single double value with a custom output precision:

writer.StartArray()
    .Double(1.2345) // == Double(..., writer.GetDoublePrecision())
    .Double(1.2345678,9) // explicit precision
    .EndArray();

An additional unit test Writer.DoublePrecision is added as well.
See upstream issues

pah added 3 commits June 25, 2014 14:18
Writing a double to an OutputStream current prints at most 6 significant
digits (according to the C standard).

The function SetDoublePrecision(), added to the Writer classes
can be used to fluently set the precision, i.e. the number of
significant digits to use for writing the double:

  Writer<...> writer(...);
  d.Accept(writer.SetDoublePrecision(12));
As proposed in other patches, it is convenient to pass a user-defined
precision for the (programmatic) output of a single double value
to an OutputStream.

This patch adds an additional overload with an explicit precision
argument to the (Pretty)Writer class templates.
@pah
Copy link
Contributor Author

pah commented Jun 25, 2014

Closing, to be resubmitted against master.

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.

1 participant