Code Comments
Programming Forum and web based access to our favorite programming groups.Vikas Agnihotri wrote:
> gawk 3.1.0 on Solaris 8
>
> I was surprised that there is no built-in pow(x,y) function.
>
> Can someone help me write one? If I remember my high school math right,
> there is a way to write pow(x,y) using the builtin log/exp functions?
>
> Help? Thanks
Here's the hard way:
ln(pow(a,b)) = b * ln(a)
therefore pow(a,b) = exp(b*log(a))
Proof is left as an exercist to the reader...
Of course, you can always use the builtin function:
a^b
:-)
-Ed
--
(You can't go wrong with psycho-rats.) (er258)(@)(eng.cam)(.ac.uk)
/d{def}def/f{/Times findfont s scalefont setfont}d/s{10}d/r{roll}d f 5/m
{moveto}d -1 r 230 350 m 0 1 179{1 index show 88 rotate 4 mul 0 rmoveto}
for /s 15 d f pop 240 420 m 0 1 3 { 4 2 1 r sub -1 r show } for showpage
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.