Hacker News new | ask | show | jobs
by Chinjut 53 days ago
The fixed-size signed types of C etc are no more the actual integers, and no less modular arithmetic, than the fixed-size unsigned types. They both implement the exact same modular arithmetic for +, -, and *. It's only for other operations (ordering comparisons, or / and % which in turn are defined in C in terms of ordering structure, as in rounding towards zero) where they differ. And in either case, that ordering structure is not one commonly encountered anywhere outside of the context of fixed size computer arithmetic.

Ask an ordinary person what 3 * (1/3) or 3 * (-1/3) should come to, and they aren't going to say any of the results that you get in C for either signed or unsigned int types.

1 comments

Singed integers in C do not implement modular arithmetic. You can trust me on this.
I'd trust you a lot more if you actually pointed out something wrong with my statement.
It is wrong that signed types in C implement modular arithmetic. They have undefined behavior on overflow.
I see. That is fair, thank you for pointing this out to me.