let's rope I can make this non-sujective
Here's the thing: Sometimes, on fixed-typed languages, I restrict input on methods and functions to positive numbers by using the unsigned
types, like unsigned int
or unsigned double
, etc.
Most libraries, however, doesn't seem to think that way. Take C# string.Length
. It's a integer, even though it can never be negative. Same goes for C/C++: sqrt
input is an int
or a double
. I know there are reasons for this ... for example your argument might be read from a file and (no idea why) you may prefer to send the value directly to the function and check for errors latter (or use a try-catch block).
So, I'm assuming that libraries are way better designed than my own code. So what are the reasons against using unsigned numbers to represent positive numbers? It's because of overflow when we cast then back to signed types?