home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.arch:9359 sci.math:11264 comp.lang.misc:3024 comp.lang.fortran:3518 comp.edu:1624
- Path: sparky!uunet!mcsun!sunic!dkuug!diku!thorinn
- From: thorinn@diku.dk (Lars Henrik Mathiesen)
- Newsgroups: comp.arch,sci.math,comp.lang.misc,comp.lang.fortran,comp.edu
- Subject: Re: Scientists as Programmers (was Re: Small Language Wanted)
- Message-ID: <1992Sep9.215657.18399@odin.diku.dk>
- Date: 9 Sep 92 21:56:57 GMT
- References: <92Sep1.205116edt.669@neuron.ai.toronto.edu> <1992Sep4.162938.29237@dscomsf.desy.de> <Bu2r42.5xr@mentor.cc.purdue.edu> <id.I12T.GP4@ferranti.com>
- Sender: thorinn@tyr.diku.dk
- Organization: Department of Computer Science, U of Copenhagen
- Lines: 44
-
- >hrubin@pop.stat.purdue.edu (Herman Rubin) writes:
- >> There has been discussion on some of these groups about the lack of nxn -> 2n
- >> multiplication, where n is the integer word size;
- >> But I know of no HLL which allows writing this.
-
- peter@ferranti.com (peter da silva) writes:
- >C:
- > int a, b;
- > long c;
-
- > c = a * b;
-
- >I've used [this] on the PDP-11, and gotten the expected 2x2->4
- >multiply in the generated code.
-
- >> The use of these features is portable.
-
- >Pretty much.
-
- Peter, didn't you follow comp.lang.c when this was last hashed out?
- In C, multiplication of two integer values gives a result of type
- integer, and many compilers will be oh-so-careful and produce a
- ``correct'' integer-size result, which is then carefully sign-extended
- to a long.
-
- (Note that the 2x2->4 multiply will give the correct result if it fits
- in an int, and since an integer overflow causes undefined behaviour, a
- Standard C implementation is _allowed_ to use the 2x2->4 to implement
- the code above. However, I think that many implementors will choose to
- define that overflow produces the low-order bits of true result, and
- so they will have use 2x2->2 and sign extend.)
-
- On the other hand,
- c = (long)a * b;
- is guaranteed to give the same result as 2x2->4. Complain to your
- vendor if such an instruction exists and the C ``optimizer'' does not
- use it.
-
- [All this presupposes that long is twice as long as int. As you noted,
- that is a very non-portable assumption in C --- it's not even certain,
- I think, that there are integers of more than one size. For some uses
- it would be nice if thing were different ... but they aren't.]
-
- Lars Mathiesen (U of Copenhagen CS Dep) <thorinn@diku.dk> (Humour NOT marked)
-