Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!bloom-beacon!think!ames!ptsfa!ihnp4!homxb!mhuxt!mhuxm!mhuxo!ulysses!allegra!alice!ark From: ark@alice.UUCP Newsgroups: comp.lang.c,comp.sys.atari.st,comp.sys.amiga Subject: Re: 32bit = 16bit x 16bit Message-ID: <7349@alice.UUCP> Date: Mon, 12-Oct-87 21:35:50 EDT Article-I.D.: alice.7349 Posted: Mon Oct 12 21:35:50 1987 Date-Received: Wed, 14-Oct-87 06:41:24 EDT References: <141@kesmai.COM> Organization: AT&T Bell Laboratories, Liberty Corner NJ Lines: 29 Xref: mnetor comp.lang.c:4867 comp.sys.atari.st:5654 comp.sys.amiga:9342 In article <141@kesmai.COM>, dca@kesmai.UUCP writes: > Does anyone know of a commercial test suite that checks to make sure that > y = x * x where x is a 16 bit int and y is long (32 bits) produces garbage > instead of the proper result? Garbage *IS* the proper result. If x is a 16-bit number, x*x is also a 16-bit number. The result of overflow is undefined. If you want the 32-bit product of x and x on a machine with 32-bit longs, the way to write it is (long) x * (long) x or x * (long) x or (long) x * x while is evaluated as ((long) x) * x You can then flame at your compiler vendor for not being smart enough to generate a single instruction for the expression (in fact, some compilers are smart enough).