auto const wasE = *in == 'e' || *in == 'E';
constexpr const char* maxInt = "9223372036854775807";
- constexpr const char* minInt = "9223372036854775808";
+ constexpr const char* minInt = "-9223372036854775808";
constexpr auto maxIntLen = constexpr_strlen(maxInt);
-
+ constexpr auto minIntLen = constexpr_strlen(minInt);
if (*in != '.' && !wasE && in.getOpts().parse_numbers_as_strings) {
return integral;
if (*in != '.' && !wasE) {
if (LIKELY(!in.getOpts().double_fallback || integral.size() < maxIntLen) ||
- (integral.size() == maxIntLen &&
- (integral <= maxInt || (integral == minInt && negative)))) {
+ (!negative && integral.size() == maxIntLen && integral <= maxInt) ||
+ (negative && integral.size() == minIntLen && integral <= minInt)) {
auto val = to<int64_t>(integral);
in.skipWhitespace();
return val;
EXPECT_EQ(847605071342477612345678900000.0,
parseJson("{\"a\":847605071342477612345678912345}",
opts).items().begin()->second.asDouble());
+ EXPECT_EQ(
+ toJson(parseJson(R"({"a":-9223372036854775808})", opts)),
+ R"({"a":-9223372036854775808})");
}
TEST(Json, ParseNumbersAsStrings) {