You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
On one hand, it may be nice to define integers to work this way, since this is probably how it will work on every machine. It would certainly be the least surprising. On the other hand, in the spirit of "communicate intent precisely", it isn't that hard to use appropriate functions for "serializing" integers as twos complement. This puts fewer limitations on the optimizer, and potentially could let us do some interesting safety features, with unused bits.
So in the light of this, if even C and C++ plan to change their design (and they've always supported a wide range of architectures even exotic ones), I think it would be a great idea for zig.
andrewrk
added
accepted
This proposal is planned.
proposal
This issue suggests modifications. If it also has the "accepted" label then it is planned.
labels
Dec 31, 2020
The reasoning here is similar to our choice to have explicitly sized integers instead of platform-dependent bit widths. Zig chooses correctness over performance here. This decision means that code that uses bitwise operators or @clz/@ctz is portable. It is also consistent with the decision on floats, to standardize IEEE754 behavor. This decision does not preclude a language extension or library adding ones complement or other integer or floating point types, but the uXX and iXX types are guaranteed to have twos complement representation.
Thanks to this reddit post for the question.
On one hand, it may be nice to define integers to work this way, since this is probably how it will work on every machine. It would certainly be the least surprising. On the other hand, in the spirit of "communicate intent precisely", it isn't that hard to use appropriate functions for "serializing" integers as twos complement. This puts fewer limitations on the optimizer, and potentially could let us do some interesting safety features, with unused bits.
Note that currently according to the language reference, floats are guaranteed to have IEEE binary representation. The resolution to this issue probably applies to floats as well.
The language specification (#75) depends on this issue.
Note: status quo: integers are always stored in twos complement binary representation.
The text was updated successfully, but these errors were encountered: