in reply to Re: getting a cube root
in thread getting a cube root
small math lesson for AM: just incase you didn't realize, taking the nth root of anything is the same as raising that expression/number/etc..etc..etc... to the 1/n power where n is the root you are trying to find.
to find the 5th root of x, you simply do x**(1/5), 218th root x**(1/218), you get the picture. FYI: very much respect for the question, but just not a perl way of doing it.. just a math way. You can write your own sub to do it if you really wanna make it readable for newbies or non-coders.
#!/perl use strict; #Take the 3rd root of 8; my $root = nthRoot(8,3); print $root; #Just pull the parameters off the #@_ array as they are needed #in the return statement sub nthRoot {return (shift)**(1/shift);}
|
|---|