Re: New Book: The School of Niklaus Wirth

Jerry Leichter <jerrold.leichter@smarts.com>
21 Nov 2000 13:56:19 -0500

          From comp.compilers

Related articles
[11 earlier articles]
Re: New Book: The School of Niklaus Wirth vbdis@aol.com (2000-11-14)
Re: New Book: The School of Niklaus Wirth genew@shuswap.net (2000-11-14)
Re: New Book: The School of Niklaus Wirth gdemont@my-deja.com (2000-11-16)
Re: New Book: The School of Niklaus Wirth jerrold.leichter@smarts.com (Jerry Leichter) (2000-11-17)
Re: New Book: The School of Niklaus Wirth fjh@cs.mu.OZ.AU (2000-11-19)
Re: New Book: The School of Niklaus Wirth vbdis@aol.com (2000-11-19)
Re: New Book: The School of Niklaus Wirth jerrold.leichter@smarts.com (Jerry Leichter) (2000-11-21)
Re: New Book: The School of Niklaus Wirth gdemont@my-deja.com (2000-11-22)
Re: types, was New Book: The School of Niklaus Wirth joachim_d@gmx.de (Joachim Durchholz) (2000-11-25)
Re: types, was New Book: The School of Niklaus Wirth jerrold.leichter@smarts.com (Jerry Leichter) (2000-11-30)
Re: New Book: The School of Niklaus Wirth nr@labrador.eecs.harvard.edu (2000-11-30)
Re: types, was New Book: The School of Niklaus Wirth anton@mips.complang.tuwien.ac.at (2000-12-01)
| List of all articles for this month |
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]





Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.