3 ms·
> Unsigned does not mean "not negative", it means "modular arithmetic". It does mean "not negative" in languages with bounds checks. Like Rust.
by virtualritz 5y ago
> Unsigned does not mean "not negative", it means "modular arithmetic".
It does mean "not negative" in languages with bounds checks. Like Rust.
- whattheactualf3 5y agoIs it called "unsigned" though? In Racket (and in mathematics) we call those natural numbers. The very notion of "unsigned" was invented by video game programmers at Bell Labs. In mathematics positive numbers are still signed (they just have a positive sign).
- gumby 5y ago> The very notion of "unsigned" was invented by video game programmers at Bell Labs. PL/I had (has) unsigned integers back in the 60s, picking up the idea from earlier languages. I believe the novel datatype in PL/I was the CHARACTER type; into the 80s I was still programming machines with variable length bytes. In many ways PL/I heralded the current Ordovician stage of programming languages, with the enormous Cambrian flourishing of hardware-specific (and company-specific) languages slowly dying out. Interestingly the only surviving languages older than it, FORTRAN and LISP, are also machine-independent.
- masklinn 5y ago> Is it called "unsigned" though? Yes: https://doc.rust-lang.org/std/primitive.usize.html https://doc.rust-lang.org/std/primitive.usize.html > The pointer-sized unsigned integer type. > In Racket (and in mathematics) we call those natural numbers. Naturals have no upper bound. Most languages don't have naturals, because they do have upper bounds. Languages which do provide naturals (limited by the host machine) usually don't bother with signing segregation, and give you mathematical integers (again limited by the host machine's capabilities).
- ncmncm 5y agoUnsigned types are supported in machine language. Any language that offers access to features of the machine will support unsigned numeric types. No language supports natural numbers. The best you can get is bignums. A language that calls its numbers natural is just lying. (Likewise, integers, and reals.) "int" is not a lie, it is a hint.
- cies 5y agoThough, in idiomatic Rust I did not find the use of unsigned as mentioned in the article, signed for indexes is the norm.
- tialaramex 5y ago> in idiomatic Rust I did not find the use of unsigned as mentioned in the article, signed for indexes is the norm Huh? If you write things[n] in Rust, and n isn't usize that's an error, you can't index things with the other primitive types at all out of the box.
- berkut 5y agoWait, what? Pretty much everything for indices (at least in the stdlib) seems to be 'usize' in my experience (i.e. Vec), which is unsigned. Am I missing something?