I know the Sqr function, but how do i make a function which retrieves another root than the square root?
I tried searching the help files, but it doesn't seem that there's a built-in function to do the trick.
Anyone knows the algorithm?
Printable View
I know the Sqr function, but how do i make a function which retrieves another root than the square root?
I tried searching the help files, but it doesn't seem that there's a built-in function to do the trick.
Anyone knows the algorithm?
Bit of rough code, but it should do the trickCode:Public Function nSqr(ByVal number as Double, _
ByVal n as Double) as Double
nSqr = number ^ (1 / n)
End Function
'Usage:
Label1.Caption = nSqr(81, 4) 'returns 3
Label1.Caption = nSqr(27, 3) 'returns 3
Hope it helps :)
[Edited by r0ach on 05-19-2000 at 02:13 PM]
Or...
:cool:Code:Public Function NthRoot(num As Double, RootOrdinal As Double) As Double
NthRoot = Exp(Log(num) / RootOrdinal)
End Function
Dan
Thanks for the quick answer, guys!
For the moment i don't need the function, but i've saved it in a module for future reference. BTW I didn't know Exp(Log(num) / RootOrdinal), but I should have remembered the number ^ (1 / n). (I just learned some of it in highschool.)
Cheers