From: | Jerry Leichter <jerrold.leichter@smarts.com> |
Newsgroups: | comp.compilers |
Date: | 21 Nov 2000 13:56:19 -0500 |
Organization: | System Management ARTS |
References: | 00-11-046 00-11-082 00-11-120 00-11-122 00-11-133 |
Keywords: | types |
Posted-Date: | 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 super-range, with results restricted to the subrange. You
can't get modulo-2^k arithmetic this way if you didn't have it to
begin with - and signed arithmetic is *not* modulo-2^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 side-effect of the type system.
-John]
Return to the
comp.compilers page.
Search the
comp.compilers archives again.