Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10 beta 3/9/83; site desint.UUCP Path: utzoo!watmath!clyde!bonnie!akgua!sdcsvax!sdcrdcf!trwrb!desint!geoff From: geoff@desint.UUCP (Geoff Kuenning) Newsgroups: net.lang.c Subject: Re: C language hacking Message-ID: <219@desint.UUCP> Date: Wed, 14-Nov-84 16:14:34 EST Article-I.D.: desint.219 Posted: Wed Nov 14 16:14:34 1984 Date-Received: Fri, 16-Nov-84 07:04:30 EST References: <5715@brl-tgr.ARPA> Distribution: net Organization: his home computer, Thousand Oaks, CA Lines: 43 In article <5715@brl-tgr.ARPA> Doug Gwyn writes: >I find that frequently I need both the quotient and remainder of >two integers: a / b a % b >Since most (maybe all) machine architectures compute these at the >same time, it sure would be nice to be able to get both results >rather than wastefully reexecuting precisely the same instructions >a second time. This becomes particularly bothersome when "a" & "b" >are fairly complicated expressions. I have no idea what a good >syntax for such an operation would be. This is the business of the optimizer, not the programmer. Even a peephole optimizer should be able to handle: x = a / b; y = a % b; and any optimizer that can handle common subexpressions can take care of this even when a and b are complex expressions. C already has too many "features" that are basically ways for the programmer to compensate for poor optimizers. Let's move into the 20th century here. >It would also be nice if sin( x ) and cos( x ) could be computed >simultaneously with reduced cost. I doubt if this is possible >but would like to know if it is. It is. The obvious way is to make use of the identity sin (x) == sqrt (1 - cos (x) * cos (x)) which can be computed slightly faster than sin(x) on some architectures. I think that there are also numerical algorithms that generate both functions at once, though I am out of my field here. I know I have run into a routine (in the Evans and Sutherland Picture System library?) named 'sincos', which returned both values at once for use in rotation calculations, but it may have been fixed-point. -- Geoff Kuenning First Systems Corporation ...!ihnp4!trwrb!desint!geoff