Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Conversation

@tannergooding
Copy link
Member

This ensures that custom-format strings that are requesting between 1-15 digits continue printing the same as before (as was the case with the standard-format strings). For custom-format strings in particular, and unlike standard-format strings, they will also continue printing the same number of digits as before when the custom-format string is requesting above 15 digits. I do think it would be desirable to "pre-parse" the custom-format string and determine exactly how many digits the user is requesting (and I believe we could do so in a way that does not cause a perf-regression and that may actually provide some perf-gains for common cases), but that is a more-involved change.

@tannergooding
Copy link
Member Author

CC. @danmosemsft, @jkotas, @stephentoub


// SinglePrecisionCustomFormat and DoublePrecisionCustomFormat are used to ensure that
// custom format strings return the same string as in previous releases when the format
// would return x digits or less (where x is the value of the corresponding constant).
Copy link
Member Author

Choose a reason for hiding this comment

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

This part in particular (returning the same string as before when less than x digits are requested) is also true for standard-numeric format strings. For the standard-formats, we only differ when more than 15 digits are requested and for the default case on G and R.

@jkotas
Copy link
Member

jkotas commented Feb 11, 2019

Is there going to be a matching corefx test update/addition?

@jkotas
Copy link
Member

jkotas commented Feb 11, 2019

I would be ok with me to wait until somebody reports it as a real problem; but if you would like to do it now - that is fine with me as well.

@tannergooding
Copy link
Member Author

Is there going to be a matching corefx test update/addition?

Yes. I plan on adding some tests to cover this code-path.

@tannergooding
Copy link
Member Author

tannergooding commented Feb 11, 2019

I would be ok with me to wait until somebody reports it as a real problem; but if you would like to do it now - that is fine with me as well.

For this particular case, I feel it is better to cover it now. Not specifying an explicit precision means that the digit generator will produce the shortest roundtrippable string, rather than the first 'X' significant digits. This results in cases where the number differs and it is not clearly better. As an extreme example, you have values like double.Epsilon where the digit generator will produce 5 rather than 494065645841247. Then, when formatting if the user has requested 2 significant digits, they will get just 5E-324 rather than 4.9E-324.

For people who are relying on custom-format strings (who are likely users expecting a particular format) to return the requested number of digits, this is a significant breaking change (especially for common cases like "0.00" or "0.0E0"). I have, in general, tried to ensure that users explicitly requesting a given number of digits are getting exactly what they requested (and for requests less than 15 digits, we can make this completely non-breaking).

@tannergooding
Copy link
Member Author

Also CC. @eerhardt who was reviewed many of the previous changes here.

char fmt = ParseFormatSpecifier(format, out int precision);
byte* pDigits = stackalloc byte[DoubleNumberBufferLength];

if (fmt == '\0')
Copy link
Member

Choose a reason for hiding this comment

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

(super nit): I think we should be consistent with how we are checking the fmt variable in this method.

Here we are using fmt == '\0'. Below: fmt != 0.

Copy link
Member Author

Choose a reason for hiding this comment

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

I can update the below one in a separate PR.

I think explicitly checking '\0' makes it much clearer that we are checking for the terminating null.

@tannergooding
Copy link
Member Author

Any other feedback here, or is this good to merge?

@tannergooding tannergooding merged commit 556e22d into dotnet:master Feb 13, 2019
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

3 participants