You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
long l = long.MaxValue; //9223372036854775807
[TestMethod]
public void TestMethod1()
{
JSONNode n = JSON.Parse($"{{ \"test\": {l} }}");
Debug.WriteLine(l);
Debug.WriteLine(n["test"].AsLong);
}
returns:
9223372036854775807
-9223372036854775808
using long.MaxValue-1
returns:
9223372036854775806
-9223372036854775808
if (isLong && !rval.ToString("F0").Equals(token))
can I think be replaced by if (longAsString && !rval.ToString("F0").Equals(token))
which saves one conversion.
Another (quite radical) solution would be to replace the m_Data fields by a overlayed struct as
[StructLayout(LayoutKind.Explicit, Pack = 1)]
struct Data
{
// Stores a value indicating which field at offset to access.
[FieldOffset(0)]
public double d;
[FieldOffset(0)]
public long l;
[FieldOffset(8)]
public byte kind;
}
However structs have some issues when trying to modifying it's fields.
Hi
I changed the code of ParseElement a bit so it has some checks on long values near their min/max (see https://wvdvegt.wordpress.com/2018/04/26/double-precision-issues/ for details on the issue):
into
Fix can probably optimized a bit by mainly using the rval.ToString("F0").Equals(token) check
The text was updated successfully, but these errors were encountered: