Risto Lankinen said:
Hi!
The discussion seems to be concentrating on whether, as a
bogus result of a buggy calculation, -1 is better than 4G. To
me they're both just plain wrong,
Absolutely. As I have said previously, whether you use signed or
unsigned, if this happens, you have a bug somewhere. Either way, it's
the same bug.
which strongly hints that
some kind of a guard should be inserted before the potentially
buggy calculation:
SOME_int a,b,result;
if( a<b ) throw SillyArgs(a,b);
result = a-b;
Now, if you agree with me so far (and I¨'d like to hear why,
if not),
I do
then isn't unsigned just a plain simple extension of the
allowable range of results, more than doubling from 2G-1 to
4G-1 (in systems where int = 32-bit)? For most applications
this probably doesn't make a big difference, but the point is
that for some others it will!
Yes, that's all it is. And that's a special case. If you are using
unsigned in preference to signed because you know you will have values
above 2G-1, you are already into implementation specific details about
the range of the types. But special cases happen, which is why I never
said I wanted unsigned banned.
Finally, if 2-3 != 4G bothers you now, then won't 2 / 3 != 0
bother you next? There is a reason for why we don't use
Complex<double> for everything, though it apparently would
let us forget about number domain problems for good (but
only apparently).
It is not the numerical value I end up with that bothers me. 2 - 3 is
illustrative. The problem I have is that, in the world of arithmetic
that I have grown up with since before I ever saw a computer, the
result of subtracting a positive integer from another positive integer
is not, in general, positive.
Yes, I know how unsigned arithmetic works in C++. But I don't want to
bother with the extra workload of having to think about it, when there
is a signed type available that loses me nothing [*] and behaves the
same way as all integers have always behaved, since I first learnt
about them at school.
[*] outside of special cases like your example above.