views:

656

answers:

2

I have this bit of VB6 sliced out of a project I'm working on:

Public Function C_Ln(c As ComplexNumber) As ComplexNumber
    Set C_Ln = toComplex(Log(C_Abs(c)), Atan2(c.Imag, c.Real))
End Function

The VB6 Log() function is base-e. I'd like to cook up versions of this to do base-2, base-10 and base-n. Where do I start?

+7  A: 
molf
and that still works okay for complex numbers? Sorry if I appear naive, it's because I am (w.r.t. complex numbers)
boost
That works fine with complex numbers, however complex logs are infinitely valued. Your formula would calculate only the principal branch, but that's probably good enough. In practice, no one likes an infinitely valued function.
Rhythmic Fistman
@boost, yes, see: http://en.wikipedia.org/wiki/Complex_logarithm#Logarithms_to_other_bases (but note that a complex number has more than one logarithm).
molf
+1  A: 

If you divide the natural log of x by the log of the base you want to achieve you get the desired result, i.e. (ln x)/(ln n) = y

See here for an explanation

Rich Seller