3 ms·
Unsigned ints are the non-negative integers mod 2^n. Signed ints behave like the integers in some tiny subset of representable values. Maybe it's something lik
by MathMonkeyMan 1y ago
Unsigned ints are the non-negative integers mod 2^n.
Signed ints behave like the integers in some tiny subset of representable values. Maybe it's something like the interval (-sqrt(INT_MAX), sqrt(INT_MAX)).
- AlotOfReading 1y agoThat's one way of looking at them. You can also look at the signed integers as bounded 2-adic numbers.
- LegionMammal978 1y ago"Bounded 2-adic integers" would only make sense if you were bounding the 2-adic norm. Integers mod 2^n would be closer to "approximate fixed-point 2-adic integers". (Alas, most languages don't expose a convenient multiplicative inverse for their integer types, and it's a PITA to write a good implementation of the extended Euclidean algorithm every time.)
- sjrd 1y agoSigned ints are also the integers mod 2^n. The beauty of modular arithmetics is that it's all equivalent. At least for all the operations that work in modular arithmetics in the first place. They just have different canonical representatives for their respective equivalence classes, which are used for the operations that don't work in modular arithmetics (like divisions, comparisons or conversions to string with a sign character).
- SkeuomorphicBee 1y agoNot in C. In C signed integer overflow is underined behaviour that may or may not be compiled to the equivalent of mod arithmetic dependingonthe whims of the compiler.
- adastra22 1y agoC oddities should be relegated to a footnote, not define what computer science is.