fullserializer icon indicating copy to clipboard operation
fullserializer copied to clipboard

Error when Parsing double.MaxValue

Open hasanbayatme opened this issue 6 years ago • 2 comments

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.

hasanbayatme avatar May 27 '18 07:05 hasanbayatme

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 avatar May 27 '18 12:05 SugoiDev

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.

SugoiDev avatar May 27 '18 13:05 SugoiDev