6 ms·
True, but we also have to be careful about teaching ints as the computer version of integers.
by munchler 1y ago
True, but we also have to be careful about teaching ints as the computer version of integers.
- jrvieira 1y agowait, why?
- neepi 1y agoProper integers aren’t bounded. Computer ints are.
- jrvieira 1y agoUnbounded 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 :)
- layer8 1y agoUnbounded 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.
- adastra22 1y agoIn many langue’s (e.g. Python, so not even obscure languages), ints are unbounded.
- layer8 1y agoThat’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”.
- MathMonkeyMan 1y agoUnsigned 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.