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

Error when Parsing double.MaxValue #155

Open
hasanbayatme opened this issue May 27, 2018 · 2 comments
Open

Error when Parsing double.MaxValue #155

hasanbayatme opened this issue May 27, 2018 · 2 comments

Comments

@hasanbayatme
Copy link

Hi.

Today I have tried to serialize and deserialize double.MaxValue using this serializer and fall into this error caused when deserializing:

Exception: Error while parsing: Bad double format with 1.79769313486232E+308; context = <.79769313486232E+308>
FullSerializer.fsResult.AssertSuccess ()
FullSerializer.fsJsonParser.Parse (System.String input)

It only caused when using double.MaxValue as far as I know.

Any help is greatly appreciated.
Thanks.

@SugoiDev
Copy link
Collaborator

Oh, that's bigger than double.MaxValue.
It happens because the "r" specifier was not used when converting the double to string with .ToString() to convert the double into a string (which causes it to overflow due to rounding).

I'll take a better look in a bit.

@SugoiDev
Copy link
Collaborator

In fsJsonPrinter.ConvertDoubleToString(), try changing the line

string doubledString = d.ToString(CultureInfo.InvariantCulture);

to

string doubledString = d.ToString("R", CultureInfo.InvariantCulture);

Notes:

  • You also need to update the FloatJitterTests.cs file (to use the "R" specifier in its ToString()), if you're using it.

  • There might be issues with "R" not properly round tripping on certain circumstances. See: https://msdn.microsoft.com/en-us/library/kfsatb94(v=vs.110).aspx An alternative would be use G17 instead, but that would add jitter and we would have to handle it differently.

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

No branches or pull requests

2 participants