Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!jarthur!uunet!munnari.oz.au!goanna!ok From: ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) Newsgroups: comp.lang.c Subject: Re: # to the nth power Message-ID: <4189@goanna.cs.rmit.oz.au> Date: 2 Nov 90 08:24:50 GMT References: <90305.005050CJH101@psuvm.psu.edu> <15984@mentor.cc.purdue.edu> Organization: Comp Sci, RMIT, Melbourne, Australia Lines: 15 In article <15984@mentor.cc.purdue.edu>, edgincd2@mentor.cc.purdue.edu (Chris Edgington *Computer Science Major*) writes: > I don't know if this is what you are looking for, but this is a neat little > trick to take a number to a power. > Answer = exp(ln(Root)*Exponent); *Please* don't do that. If you want to raise a number x to an integral power n, use pow(x, (double)n). That can handle negative numbers x (x < 0), while exp(ln(x)*n) can't. If you want to raise a number x to a non-integral power y, use pow(x, y). Why? Because it can be a _lot_ more accurate. (If you want to know why, read Cody&Waite.) -- The problem about real life is that moving one's knight to QB3 may always be replied to with a lob across the net. --Alasdair Macintyre.