Brad Roberts wrote:
On Thu, 1 Oct 2009, Saaa wrote:
I think is very bug-prone, isn't it obvious iub should be -5?
ubyte ub = 5;
int iub = -ub; // iub now is 251
What is the reasoning to do it this way?
The inclusion of the 'int' part obscures what I think the real problem
is..
Does it make sense to use uniary-minus on a unsigned type?
My answer.. no.
I agree. But you don't actually need unary minus to see the problem:
import std.stdio;
void main()
{
uint a = 0;
uint b = 5;
long ib = a - b;
writefln("%s", ib); // prints: 4294967291
}