adobe / json-formula

Query language for JSON documents
http://opensource.adobe.com/json-formula/
Apache License 2.0
19 stars 8 forks source link

Integer type is not defined #118

Closed Eswcvlad closed 6 months ago

Eswcvlad commented 6 months ago

In a bunch of types integer is specified as the parameter type, while integer is not directly specified in the spec and there are no coercion rules for it.

I've done some testing and in this implementation, coercion behavior varies from function to function, when you pass a floating-point number:

It would be better, if it was standardized across the board. Imo, converting to Number and then truncating the fractional part seems to be the way to go. TypeError doesn't look ideal for this, as it could cause issues in languages like JS, where numbers are treated as floats.

There are also no type size restrictions on integer either, but I assume it is not an issue, as, practically speaking, most reasonable values will fit [-(2^53 − 1), (2^53 − 1)] and there is little sense in using big integers for this, so it could be left up to implementations.

JohnBrinkman commented 6 months ago

Valid concerns. I will look at a fix.

JohnBrinkman commented 6 months ago

I don't think we can make integer a first-class data type in json-formula, since it's not a JSON data type -- and the usage doesn't occur outside of functions. I think it's best just to add some discussion in the Data Types section to describe the limited support.

Eswcvlad commented 6 months ago

I don't think we can make integer a first-class data type in json-formula, since it's not a JSON data type -- and the usage doesn't occur outside of functions. I think it's best just to add some discussion in the Data Types section to describe the limited support.

Makes sense. I was mostly concerned about inconsistent coercion.

JohnBrinkman commented 6 months ago

Update spec to say "truncate" instead of "floor"