3 ms·
I feel lucky to have gotten two's complement early. Turns out that if you truly understand two's complement, you can implement signed math in C without UB if y
by gavinhoward 3y ago
I feel lucky to have gotten two's complement early.
Turns out that if you truly understand two's complement, you can implement signed math in C without UB if you use unsigned types because overflow on unsigned types is defined.
Side note: this is another reason I won't touch Zig; UB on unsigned overflow is too high of a price to pay.
- BrianHenryIE 3y agoUB meaning "undefined behaviour", appropriately enough! (I had to look it up)
- gavinhoward 3y agoOh, I apologize! I do try to define abbreviations.
- HhbozBlqtp 3y agoI guess you didn't want to use `@addWithOverflow` or `std.math.add`?
- gavinhoward 3y agoI could, but I don't want ugly code.