Inconsistent behavior of asInt
koher opened this issue · comments
Yuta Koshizawa commented
JSON(string: "{\"n\":\(UInt32.max)}")["n"].asInt => println // clashes in 32-bit environment
JSON(string: "{\"n\":\(UInt64.max)}")["n"].asInt => println // Optional(-1)
JSON(string: "{\"n\":18446744073709551616}")["n"].asInt => println // 32-bit: clashes, 64-bit: Optional(0)
// 18446744073709551616 == 2 ** 64
I think nil
or Int.max
should be returned for all of the cases above.
It seems that asInt
for large integers in 32-bit environments clashes because simply overflow is not permitted.
Int32(UInt32.max) // clashes