Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!burl!ulysses!bellcore!decvax!decwrl!amdcad!lll-crg!topaz!bentley!kwh From: kwh@bentley.UUCP (KW Heuer) Newsgroups: net.lang.c Subject: Re: Long Longs Message-ID: <610@bentley.UUCP> Date: Tue, 4-Mar-86 12:38:15 EST Article-I.D.: bentley.610 Posted: Tue Mar 4 12:38:15 1986 Date-Received: Fri, 7-Mar-86 04:54:32 EST References: <1434@brl-smoke.ARPA> Organization: AT&T Bell Laboratories, Liberty Corner Lines: 26 In article <1434@brl-smoke.ARPA> jon@cit-vax.ARPA (Jon Leech) writes: >Getting [ a C++ "class longlong" ] to generate the 'proper' code for > int b, c, d; > longlong result; > result = (b * c) / d; >would be more difficult. If you're willing to write it result = ((longlong)b * c) / d; it will work, but it will invoke a more powerful function than it needs. >Final cautionary note: [ from K&R ] "... Expressions ... may be >rearranged arbitrarily ..." That doesn't apply here; the only way b*c/d can be rearranged by the compiler is to write it c*b/d (using commutativity of "*"). It can't be written b*(c/d), for example, because that is not mathematically correct (since x/y means floor(x/y)). It could only do the division first if it were a floating-point expression. Besides, if you're talking about an overloaded C++ operator, none of the mathematical identities are assumed: b*c/d means exactly operator/(operator*(b,c),d); the compiler makes no assumptions about the semantics. Karl W. Z. Heuer (ihnp4!bentley!kwh), The Walking Lint