disabling unary "-" for unsigned types

Walter Bright newshound1 at digitalmars.com
Tue Feb 16 10:38:06 PST 2010


Steven Schveighoffer wrote:
> What I meant by that statement is that the behavior goes against common 
> sense -- when it doesn't have to.  It only makes sense to advanced 
> programmers who understand the inner workings of the CPU and even in 
> those cases, advance programmers easily make mistakes.

Where you and I disagree is I don't feel that 2s-complement arithmetic 
is in any way an advanced programming topic. Nor is it an inner working 
of a CPU - it's an exteriorly visible behavior, well documented in the 
CPU manuals. (Inner behavior would be things like the microcode.) As I 
mentioned before, how that works was often the very first topic in an 
introductory book on programming.

No comprehension of the fundamentals computer arithmetic will lead to 
failure after failure as a programmer; no language can paper that over. 
There is no escaping it or pretending it isn't there.


> When the result of an operation is 99.999% of the time an error (in fact 
> the exact percentage is (T.max-1)/T.max  * 100), disallowing it is worth 
> making the rare valid uses of it illegal.

It conforms to the simple rules of 2s-complement arithmetic, so I 
disagree with calling it an error.


> The case I'm talking about is the equivalent to doing:
> 
> x = x / 0;

Even mathematicians don't know what to do about divide by zero. But 2's 
complement arithmetic is well defined. So the situations are not comparable.



More information about the Digitalmars-d mailing list