Lix Development | 413 Members | |
| (Technical) development of Lix, the package manager, a Nix implementation. Please be mindful of ongoing technical conversations in this channel. | 139 Servers |
| Sender | Message | Time |
|---|---|---|
| 14 Aug 2025 | ||
| the latest RFC defines a single numeric type and says This specification allows implementations to set limits on the range Note that when such software is used, numbers that are integers and | 15:37:10 | |
| * the latest RFC defines a single numeric type and says
| 15:37:16 | |
| there is an RFC that subsets it into an interoperable subset that IIRC they say that IETF specifications SHOULD use; I believe it limits the range to the interoperable subset | 15:37:39 | |
| but I'd have to check | 15:37:42 | |
Nix could just always parse numeric literals in JSON into floats, but it would be annoying. (especially since Nixpkgs backs its integer-parsing functions by fromJSON) | 15:38:05 | |
In reply to @raitobezarius:matrix.orgThanks | 15:38:15 | |
| ok, I-JSON says
| 15:38:53 | |
| ok, Nixpkgs does in fact detect the float case for integer conversions | 15:39:36 | |
| so "fits into Nix integer → Nix integer, otherwise → float" would be desirable for Nixpkgs and consistent with other JSON implementations | 15:39:58 | |
| "fits into Nix integer → Nix integer, otherwise → error" would be acceptable for that too, but less interoperable with other JSON implementations and weird per the spec | 15:40:28 | |
since adding a .0 isn't really meant to change a number by the specced JSON semantics | 15:40:39 | |
and indeed builtins.fromJSON "1.0" is 1 | 15:40:50 | |
oh wait 1.0 also prints as 1 | 15:41:01 | |
ok never mind :) | 15:41:12 | |
| anyway my point is just that we should pick one. the current behaviour is incoherent | 15:41:27 | |
| Apparently that behaviour even changed, I remember it throwing or converting to float depending on the number of digits but now the float only happens when out of the unsigned range. | 16:27:10 | |
| yes | 16:42:22 | |
| it was changed when banning overflow in the Nix language | 16:42:25 | |
| IMO that part of the change was a mistake | 16:42:31 | |
| well, it would be just a difference of opinion if the negative values were handled consistently | 16:42:44 | |
| i don't know what it should do | 16:44:22 | |
| i chose to make it behave conservatively | 16:44:40 | |
builtins.fromJSON "-9223372036854775809"'s behaviour is not conservative though | 16:46:56 | |
| see | 16:47:06 | |
| JSON has only one numeric type and we certainly want everything that fits in a Nix integer to be represented as one (because Nixpkgs expects that). so the two options are optimistically coercing JSON literals that look like Nix integers into Nix integers and leaving the rest as floats, or coercing JSON literals that look like any kind of integer into Nix integers, leaving ones that are clearly floats as floats, and rejecting the rest. currently, we do neither | 16:48:52 | |
| correct, I would class that as "a bug" | 16:49:20 | |
I think the former is what makes the most sense per JSON semantics and the general behaviour pointed at by the RFCs. the latter is defensible too. but picking one for positive values and another for negative values because of how nlohmann_json interacts with C++ numeric types not so much | 16:49:22 | |
| ok. but I think it is hard to define these erroring semantics in a way that doesn't have weird edge cases wrt how JSON works | 16:50:09 | |
| I think that getting a float in nix in general because it's nix is usually an undesired outcome | 16:50:14 | |
| for instance, there are also JSOn literal floats that cannot be represented | 16:50:22 | |