diff --git a/ujson/src/ujson/Value.scala b/ujson/src/ujson/Value.scala index bf7507687..15dbcb22f 100644 --- a/ujson/src/ujson/Value.scala +++ b/ujson/src/ujson/Value.scala @@ -180,7 +180,9 @@ object Value extends AstTransformer[Value]{ override def visitFloat64StringParts(s: CharSequence, decIndex: Int, expIndex: Int, index: Int) = { ujson.Num( - if (decIndex != -1 || expIndex != -1) s.toString.toDouble + if (decIndex != -1 || expIndex != -1 || s.length() >= 19 /*digit count of largest positive long*/) { + s.toString.toDouble + } else ParseUtils.parseIntegralNum(s, decIndex, expIndex, index).toDouble ) } diff --git a/ujson/test/src/ujson/SmallJsonTests.scala b/ujson/test/src/ujson/SmallJsonTests.scala index 11fd25eaa..f06ac1fa9 100644 --- a/ujson/test/src/ujson/SmallJsonTests.scala +++ b/ujson/test/src/ujson/SmallJsonTests.scala @@ -23,6 +23,50 @@ object SmallJsonTests extends TestSuite { } } + test("largeDouble"){ + test("longMaxValue") { + assert( + ujson.read("9223372036854775807").num == + "9223372036854775807".toDouble + ) + } + test("longMinValue") { + assert( + ujson.read("-9223372036854775808").num == + "-9223372036854775808".toDouble + ) + } + test("longMaxValuePlusOne") { + assert( + ujson.read("9223372036854775808").num == + "9223372036854775808".toDouble + ) + } + test("longMinValueMinusOne") { + assert( + ujson.read("-9223372036854775809").num == + "-9223372036854775809".toDouble + ) + } + test("issue240"){ + assert( + ujson.read("28291041994989161181883157038606177750").num == + "28291041994989161181883157038606177750".toDouble + ) + } + test("largeDecimalPoint"){ + assert( + ujson.read("28291041994989161181883157038606177750.28291041994989161181883157038606177750").num == + "28291041994989161181883157038606177750.28291041994989161181883157038606177750".toDouble + ) + } + test("largeDecimalPointExponent"){ + assert( + ujson.read("28291041994989161181883157038606177750.28291041994989161181883157038606177750E123456789").num == + "28291041994989161181883157038606177750.28291041994989161181883157038606177750E123456789".toDouble + ) + } + } test("inputsEu"){ TestUtil.checkParse( """{