News for hackers. Stuff that matters.
Re:Almost Always Unsigned by barrkel on Sunday January 02, 2022 @09:19AM (#29768857)
What you want is range subtypes of signed integers.
Re:Almost Always Unsigned by kazinator on Sunday January 02, 2022 @11:27AM (#29770071)
Important: without silent conversion. Languages like Pascal and Ada require explicit conversions in more places to make that sort of thing useful.
Re:Almost Always Unsigned by pyjarrett on Sunday January 02, 2022 @11:58AM (#29770446)
It also allows creating type checked "new" numerical types for semantics purposes to help improve interfaces. This helps prevent things like accidentally passing an integer in the wrong units for example. Two of the worst offenders I've seen of this is: "Is this uint64_t (or float) "dt" parameter in ticks, seconds, milliseconds, microseconds or nanoseconds?" and "Is this angle parameter in radians or degrees?"