Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!mcsun!hp4nl!philapd!ssp9!dolf From: dolf@idca.tds.PHILIPS.nl (Dolf Grunbauer) Newsgroups: comp.lang.c Subject: Re: # to the nth power Message-ID: <522@ssp9.idca.tds.philips.nl> Date: 2 Nov 90 08:23:08 GMT References: <90305.005050CJH101@psuvm.psu.edu-> <15984@mentor.cc.purdue.edu-> <9750@helios.TAMU.EDU> <1990Nov1.232830.17131@NCoast.ORG> Reply-To: dolf@idca.tds.philips.nl (Dolf Grunbauer) Organization: Philips Information Systems, Apeldoorn, The Netherlands Lines: 37 In article <1990Nov1.232830.17131@NCoast.ORG> catfood@NCoast.ORG (Mark W. Schumann) writes: 1; i--) result *= root; Oeps, I think this one ---^ should be a 0 < return result; < } A quicker version (throw in a few registers if still not fast enough): int powi (int root, int exponent) { int result = 1; while (exponent > 0) { while (!(exponent & 1)) { root *= root; exponent /= 2; } result *= root; exponent--; } return result; } = 0; -- _ _ / U | Dolf Grunbauer Tel: +31 55 433233 Internet dolf@idca.tds.philips.nl /__'< Philips Information Systems UUCP ...!mcsun!philapd!dolf 88 |_\ If you are granted one wish do you know what to wish for right now ?