Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
Integer schemas silently change the value of large ints, overflow to negative values #2378
Dgraph's tour explains that the int schema is a 64-bit signed integer. However, on Dgraph 5b93fb4,
Notice that numbers above 9007199254740992N--2^53+1--are not exactly representable, and are remapped to numbers that would fit in an IEEE 754 double precision float. I think this behavior also interacts with a later coercion to signed ints, because...
Numbers above 9223372036854775296 are pinned to -9223372036854775809, which is -2^63. I thiiiink what's happening here is that the floating-point coercion is pushing these values up to 2^64, which causes an unchecked signed integer overflow, and wraps over to -2^63.
You can reproduce this with 56dce4d5b875bc2eec841564f865b72168c91938 by running
So, a bit of backstory, @aphyr went and posted this on Twitter after my comments here: https://twitter.com/aphyr/status/997148938028318720.
And found that there's thing called json.Number -- which I didn't know about. So, it looks like by using Json.Number, we might be able to correctly tell if it's an int64 or a float64. I'll work on implementing that today, to see if we can now correctly parse numbers.
This is the Go Play code, which can correctly determine int64 vs float64: