Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!rutgers!ames!amdahl!amdcad!tim From: tim@amdcad.AMD.COM (Tim Olson) Newsgroups: comp.lang.c Subject: Re: MSC C arithmetic Message-ID: <17978@amdcad.AMD.COM> Date: Thu, 20-Aug-87 12:40:42 EDT Article-I.D.: amdcad.17978 Posted: Thu Aug 20 12:40:42 1987 Date-Received: Sat, 22-Aug-87 10:39:10 EDT References: <8792@brl-adm.ARPA> <305@wrs.UUCP> <2042@umn-cs.UUCP> Reply-To: tim@amdcad.UUCP (Tim Olson) Organization: Advanced Micro Devices, Inc., Sunnyvale, Ca. Lines: 26 In article <2042@umn-cs.UUCP> randy@umn-cs.UUCP (Randy Orrison) writes: +----- |Since the compiler is free to evaluate the expression in whatever order is |wants, does that mean that it is not determined what types it will use? |It seems to me that both of the following are legal: | | repeat_cnt * units * blksiz * 16.0 | --int-- --double-- | --double-- |and | 16.0 * blksiz * units * repeat_cnt | --double-- | --double-- | --double-- | |Which we know can give different results. Is this right? (under K&R and ANSI) +----- Yup. To guarantee that the calculation is done correctly, you should write it: 16.0 * (double)blksiz * (double)units * (double)repeat_cnt; -- Tim Olson Advanced Micro Devices (tim@amdcad.amd.com)