From:  Jerry Leichter <jerrold.leichter@smarts.com> 
Newsgroups:  comp.compilers 
Date:  21 Nov 2000 13:56:19 0500 
Organization:  System Management ARTS 
References:  0011046 0011082 0011120 0011122 0011133 
Keywords:  types 
PostedDate:  21 Nov 2000 13:56:19 EST 
 >There are two reasons for wanting an unsigned type:
 >
 >  To extend the range of small integers....
 >  To implement "modulo arithmetic"....

 The trouble with just using a subtype for unsigned arithmetic is that
 you lose one bit....
Arithmetic on a subrange, to make any sense, is the same as arithmetic
on the superrange, with results restricted to the subrange. You
can't get modulo2^k arithmetic this way if you didn't have it to
begin with  and signed arithmetic is *not* modulo2^k arithmetic.
If you want modulo arithmetic operators, you need to explicitly put
them into the language. Whether you put them in on their own, or make
up a whole type to go along with them, is a design choice.
 Jerry
[Someone else noted that unsigned types can also be useful to map onto
hardware registers where the contents aren't signed numbers. But I do
agree that the best way to implement modular arithmetic is as modular
arithmetic, not as a somewhat obscure sideeffect of the type system.
John]
Return to the
comp.compilers page.
Search the
comp.compilers archives again.