by protonfish · 9y ago · 0 comments
Real world values are still typed.
"If you need more control ... metadata is your friend."
aka implicit user typedefs. Explicit is better.
OTOH, exact decimals (of which integers are a subset) differ fundamentally in meaning from limited precision binary (or decimal, though that's more rarely encountered) floating point approximations. Which matters in interchange as well as schema.
These are all integers. There only needs to be one integer type for all of: 0 6 -6 8000000000000000000000. Python gets this right.
Or you can go the JSON route, mumble your way through the numbers spec, let every language do its own thing, and tell the handful of people seriously interested in moving integers too large to be precisely specified by a 64-bit float to encode as strings or something and stop worrying everyone else with the complexity....
I don't follow this one. If your language, static or otherwise, is capable of turning this JSON:
"100"
into a string, and this: 100
into a number of whatever type, then it's also capable of turning this hypothetical input: 100
into one type of integer, and this: 100000000000000000000000000000000000000000000000000000000
into another type of integer.{ "int": 1, "float": 1.0 }
Of course it's up to the parser implementation to interpret 1.0 as a float.
The spec is very relaxed about the number type:
(one of my favorite things about Perl 6 is that non-integer literals are rationals by default; floating-point is only used if the literal is specified in scientific notation)
JSON.parse('[9223372036854775805]')[0] === JSON.parse('[9223372036854775806]')[0]
You should get: <- true
Is chrome's implementation broken? Those are both numbers that a signed int64 can store precisely but a double float cannot.Javascript, for example, has this problem because everything is just a "number" and the number data type is a IEEE-754 double precision float. A double precision float can't represent all int64 values, so transmitting an int64 via JSON to Javascript and using the standard JSON parser is lossy. You could say that Javascript screwed up by making number have a specific precision, and you might be right. Python, for example, gives you seamless arbitrary precision arithmetic.
But the decision to use an arbitrary precision type for all numbers in every language is definitely not appropriate. Arbitrary precision has trade offs, and sometimes it's important to work with machine integers.