Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!lll-winken!uunet!crdgw1!sungod.crd.ge.com!davidsen From: davidsen@sungod.crd.ge.com (William Davidsen) Newsgroups: comp.lang.c Subject: Davidsen's device Message-ID: <1430@crdgw1.crd.ge.com> Date: 1 Aug 89 18:07:50 GMT Sender: news@crdgw1.crd.ge.com Reply-To: davidsen@crdos1.UUCP (bill davidsen) Organization: General Electric Corp. R&D, Schenectady, NY Lines: 27 I recently discovered the following technique. While I can't swear that it's new and unique to me, I can claim independent discovery. I make no claims that it is suited to any problem you have, will have, or would admit to having. I was calculating a function and had two algorithms, one of which was 13 times faster than the other but unreliable for input values less than 1.0, the other very accurate but slow. I had to evaluate the function 6E8 times on a slow machine. Here's the code: double hacs1(), hacs2(); double asect; (*(asect < 1.0 ? hacs2 : hacs1)(asect); Since the name of a function is typed "pointer to function returning..." this was treated as "(*ptr)()" and generated the desired code. It was slightly faster than the obvious: if (asect < 1.0) hasc2(asect); else hasc1(asect); bill davidsen (davidsen@crdos1.crd.GE.COM) {uunet | philabs}!crdgw1!crdos1!davidsen "Stupidity, like virtue, is its own reward" -me