Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 ggr 10/10/85; site bentley.UUCP Path: utzoo!watmath!clyde!cbosgd!ihnp4!bentley!kwh From: kwh@bentley.UUCP (KW Heuer) Newsgroups: net.lang.c Subject: Re: Long Longs Message-ID: <608@bentley.UUCP> Date: Mon, 3-Mar-86 16:13:02 EST Article-I.D.: bentley.608 Posted: Mon Mar 3 16:13:02 1986 Date-Received: Wed, 5-Mar-86 03:56:50 EST References: <3408@umcp-cs.UUCP> <491@faron.UUCP> Organization: AT&T Bell Laboratories, Liberty Corner Lines: 37 In article <491@faron.UUCP> faron!bs (Bob Silverman) writes: >[How do I calculate without intermediate overflow] >a = (b*c)/d; >a = (b*c) % d; >... Many machines CAN multiply two full words together giving a double >length product placed in two adjacent registers. Many others can't. If the feature were built into the language, what code should it generate for "long long" arithmetic on a more limited machine? >Does C++ have long longs? C++ cannot do anything that C cannot, since it produces C output. >Does anyone have a good solution? My prefered method (to maximize portability) is to have library functions int muldiv(int, int, int) int mulrem(int, int, int) which are written in assembly language; for specific applications in tight loops I hand-optimize the .s file as described in article <3408@umcp-cs.UUCP> by umcp-cs!chris (Chris Torek) (not quoted here). It seems to me that best solution for the future is for "int" to be 32 bits wide, while "long" is 64. I expect the compilers will start doing this once there is a little more support for 64-bit arithmetic in the hardware. (Like when 32-bit addresses aren't big enough.) No smiley on this paragraph, I'm serious. Incidentally, does anyone have a muldiv routine (in C or as) for a 32-bit machine without emul/ediv instructions? Currently I'm using (int)((double)x*(double)y/(double)z) which is quite slow on a 3b2 without floating-point hardware. Karl W. Z. Heuer (ihnp4!bentley!kwh), The Walking Lint