On Thu, Nov 20, 2014 at 08:18:23AM +0000, Don via Digitalmars-d wrote: > On Wednesday, 19 November 2014 at 17:55:26 UTC, Andrei Alexandrescu wrote: > >On 11/19/14 6:04 AM, Don wrote: > >>Almost everybody seems to think that unsigned means positive. It > >>does not. > > > >That's an exaggeration. With only a bit of care one can use D's > >unsigned types for positive numbers. Please let's not reduce the > >matter to black and white. > > > >Andrei > > Even in the responses in this thread indicate that about half of the > people here don't understand unsigned. > > "unsigned" means "I want to use modulo 2^^n arithmetic". It does not > mean, "this is an integer which cannot be negative". > > Using modulo 2^^n arithmetic is *weird*. If you are using uint/ulong > to represent a non-negative integer, you are using the incorrect type. [...]
By that logic, using an int to represent an integer is also using the incorrect type, because a signed type is *also* subject to module 2^^n arithmetic -- just a different form of it where the most negative value wraps around to the most positive values. Fixed-width integers in computing are NOT the same thing as unrestricted integers in mathematics. No matter how you try to rationalize it, as long as you use hardware fix-width "integers", you're dealing with modulo arithmetic in one form or another. Pretending you're not, is the real source of said subtle bugs. T -- Why waste time learning, when ignorance is instantaneous? -- Hobbes, from Calvin & Hobbes