Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
lihaoyi committed Jul 9, 2023
1 parent 8723cae commit 751d42d
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
4 changes: 3 additions & 1 deletion ujson/src/ujson/Value.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}
Expand Down
44 changes: 44 additions & 0 deletions ujson/test/src/ujson/SmallJsonTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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(
"""{
Expand Down

0 comments on commit 751d42d

Please sign in to comment.