Closed Eswcvlad closed 6 months ago
Valid concerns. I will look at a fix.
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.
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.
Update spec to say "truncate" instead of "floor"
In a bunch of types
integer
is specified as the parameter type, whileinteger
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:
Truncate the fractional part:
TypeError:
Other:
name
just gets coerced to string instead.find("m", "abm", 0.7)
returns2.7
.name
just gets coerced to string instead.mid("Fluid Flow", 0.1, 4.9)
returnsFluid
instead ofFlui
.round(1.95583, 3.8)
returns1.9557581994970148
.search("a?c", "acabc", 1.2)
returns1.2
.substitute("aaaa", "a", "b", 1.2)
returns "aaaa".trunc(8.9122345, 4.1)
returns8.912203927959501
.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.