r/ProgrammingLanguages • u/Nuoji C3 - http://c3-lang.org • May 03 '26
Blog post Unsigned Sizes: A Five Year Mistake
https://c3-lang.org/blog/unsigned-sizes-a-five-year-mistake/
91
Upvotes
r/ProgrammingLanguages • u/Nuoji C3 - http://c3-lang.org • May 03 '26
View all comments
Show parent comment
1
u/matthieum May 05 '26
is the hard cut-off at 0 which screws up arithmetic rules.
In fact, wrap-around behavior, despite being strange initially, plays nice. With wrap-around,
i + (j - i) == j, no matter what valuesiandjhave, because in case of overflow (i > j), the two overflows cancel each other out like magic.So from a mathematical intuition point of view, wrap-around means you can take an algorithm that's correct in infinite bit-width maths, and use with finite bit-width, and still get the correct result.
This does NOT work as well with trapping. Trapping means that
+is no longer associative (!), for example. Surprise!Note: I am not exactly advocating for wrap-around, it has its own issues.