For Programmers: Free Programming Magazines  


Home > Archive > AWK > September 2004 > Re: pow(x,y) function









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: pow(x,y) function
E. Rosten

2004-09-20, 8:56 pm

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

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com