fullserializer
fullserializer copied to clipboard
Error when Parsing double.MaxValue
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.
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.
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.