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

Roundtrip string format for single/double doesn't roundtrip -0 #9883

Closed
mconnew opened this issue Mar 6, 2018 · 0 comments
Closed

Roundtrip string format for single/double doesn't roundtrip -0 #9883

mconnew opened this issue Mar 6, 2018 · 0 comments

Comments

@mconnew
Copy link
Member

@mconnew mconnew commented Mar 6, 2018

The string format "R" is supposed to allow you to get back the same value as you initially had. When the value is negative zero, the negative gets dropped and the value does not round trip. This can be easily seen when dividing 1 by the value as you will get either positive or negative infinity.

double initialValue = -0.0;
string valueString = initialValue.ToString("R", CultureInfo.InvariantCulture);
double roundTripped = double.Parse(valueString, CultureInfo.InvariantCulture);
Console.WriteLine("1 / initialValue : " + 1 / initialValue);
Console.WriteLine("1 / roundTripped : " + 1 / roundTripped);

// Output:
// 1 / initialValue : -∞
// 1 / roundTripped : ∞
@tannergooding tannergooding self-assigned this Sep 11, 2018
@msftgits msftgits transferred this issue from dotnet/coreclr Jan 31, 2020
@msftgits msftgits added this to the Future milestone Jan 31, 2020
@tannergooding tannergooding removed their assignment May 26, 2020
@msftbot msftbot bot locked as resolved and limited conversation to collaborators Dec 18, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants