Skip to content

Commit 4e75231

Browse files
author
Bartel Van Nieuwenhuyse
committed
Use different bounds: numeric limits of double instead of int64_t
1 parent c122300 commit 4e75231

2 files changed

Lines changed: 20 additions & 5 deletions

File tree

include/jsoncons_ext/jmespath/jmespath.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,8 +1240,8 @@ namespace detail {
12401240
template <typename Json>
12411241
class jmespath_evaluator
12421242
{
1243-
static constexpr double max_double_to_int64 = 9223372036854775807.0;
1244-
static constexpr double min_double_to_int64 = -9223372036854775808.0;
1243+
static constexpr double max_double_to_int64 = static_cast<double>(uint64_t(1u) << std::numeric_limits<double>::digits); // 2^53
1244+
static constexpr double min_double_to_int64 = -static_cast<double>(uint64_t(1u) << std::numeric_limits<double>::digits); // -2^53
12451245

12461246
public:
12471247
typedef typename Json::char_type char_type;

test/jmespath/input/test.json

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,24 @@
8282
"result": "-3"
8383
},
8484
{
85-
"comment": "Ceil function applied to a large double not in int64_t range should return as double",
86-
"expression": "ceil(`1e20`)",
87-
"result": 1e20
85+
"comment": "Value at 2^53 boundary (max safe integer)",
86+
"expression": "ceil(`9007199254740992.0`)",
87+
"result": 9007199254740992
88+
},
89+
{
90+
"comment": "Negative value at -2^53 boundary",
91+
"expression": "floor(`-9007199254740992.0`)",
92+
"result": -9007199254740992
93+
},
94+
{
95+
"comment": "Value beyond safe range remains as double (does not overflow to negative integer)",
96+
"expression": "ceil(`9223372036854775807.2`)",
97+
"result": 9.223372036854776e+18
98+
},
99+
{
100+
"comment": "Negative value beyond safe range remains as double",
101+
"expression": "floor(`-9223372036854775808.2`)",
102+
"result": -9.223372036854776e+18
88103
}
89104
]
90105
}

0 commit comments

Comments
 (0)