Re:Most ints are not floats
by munchler on Sunday June 29, 2025 @03:44PM
(#44415768)
True, but we also have to be careful about teaching ints as the computer version of integers.
[ Parent
| on HN ]
wait, why?
Proper integers aren’t bounded. Computer ints are.
Unbounded integer types exist, which have infinite precision in theory and are only limited by available memory in practice.
You can make the argument that "proper" integers are also bounded in practice by limitations of our universe :)
Unbounded integer types aren't ints.
The important point is that the arithmetic operators on int perform modulo arithmetics, not the normal arithmetics you would expect on unbounded integers. This is often not explained when first teaching ints.
In many langue’s (e.g. Python, so not even obscure languages), ints are unbounded.
That’s not the notion of ints the article, nor GP by “computer ints”, was referring to. Python is rather atypical in its nomenclature here. Arbitrary-precision integers are generally called “integer” or something like “bigint”.
Re:Most ints are not floats
by MathMonkeyMan on Sunday June 29, 2025 @04:33PM
(#44416209)
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)).
Signed 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).
Re:Most ints are not floats
by SkeuomorphicBee on Sunday June 29, 2025 @06:55PM
(#44417366)
Not 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.
C oddities should be relegated to a footnote, not define what computer science is.
Re:Most ints are not floats
by AlotOfReading on Sunday June 29, 2025 @05:19PM
(#44416517)
That's one way of looking at them. You can also look at the signed integers as bounded 2-adic numbers.
Re:Most ints are not floats
by LegionMammal978 on Sunday June 29, 2025 @05:45PM
(#44416738)
"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.)