JMESPath functions floor and ceil return integer#688
JMESPath functions floor and ceil return integer#688BartelNieuwenhuyse wants to merge 5 commits intodanielaparker:masterfrom
Conversation
| case json_type::float64: | ||
| { | ||
| return *context.create_json(std::ceil(arg0.template as<double>())); | ||
| return *context.create_json(static_cast<int64_t>(std::ceil(arg0.template as<double>()))); |
There was a problem hiding this comment.
Is there a way to cast to the underlying type of json_type::int64 instead of to int64_t?
There was a problem hiding this comment.
For the int64/uint64 case, instead of
return *context.create_json(arg0);
you can safely return arg0.
For the float64 case, you should
- check if the double value is
nanorinfusingstd::finite, and if so, setectojmespath_errc::invalid_typeand return null. - check if the return value of
std::ceil/std::flooris inside the range of anint64_tbefore doing the cast, and if it isn't, I would suggest leaving it as a double (the alternative would be to convert it to atypename Json::string_typeand return it as aJsonstring value with asementic_tag::biginttag)
Regarding,
Is there a way to cast to the underlying type of json_type::int64 instead of to int64_t?
there isn't, but the underlying type is always int64_t.
There was a problem hiding this comment.
I'm not sure if defining the numbers is an option, but I seem to hit warnings in my other attempts to define the largest\smallest double that can be safely converted to int64_t.
|
The cases that fail are failing because a double doesn't have enough precision to represent |
…t way of computing the max\min
JMESPath function floor and ceil return a json float number, while the specs and the examples in it suggest that an integer should be returned.
Expected:
floor(`3.7`) -> 3Actual:
floor(`3.7`) -> 3.0