Differences between ZON and Zig

There are differences between ZON and Zig:

  1. ZON has nan, inf, -inf literals, zig does not.

Side note: are -0.0 and +0.0 literals needed?

Should these differences be eliminated (add these literals to zig)?

  • Add those special float literals to zig
  • Remove those special float literals from zon
  • Do nothing and accept the difference between zig and zon
0 voters

I think the general movement is towards disallowing these states to make it easier to find bugs: Disallow NaN and inf for `comptime_float` · Issue #21205 · ziglang/zig · GitHub (accepted)
Proposal: Make floats non-NaN by default · Issue #11234 · ziglang/zig · GitHub (proposed)

5 Likes

Here is another related accepted proposal:

4 Likes

I think ZON should be capable of representing the semantics of IEEE floats, don’t you agree? If you expect a ZON formatted response from a server, what would you expect it to return for 0/0?

This also begs the question of if ZON should have error literals too… (error.InvalidRequest)

2 Likes

The reason why these literals exist in zon, but not in zig, is that in zig, you can simply do std.math.nan(type)/std.math.inf(type), which is impossible in zon. So as long as float types in zig can represent inf and nan (which is required as long as zig floats should be compatible with e.g. c floats) and zon floats are compatible with zig floats, converting inf or nan to zon should result in something. Another idea I just had (I’m not sure if I like it) is to have something like -1/0, 0/0, 1/0 as zon literals.

4 Likes