2

LibreOffice has function LOG(x;n) where you can define your own base.

However, when I use Macro to write function in Basic, It does not take second parameter into account thus calculating natural logarithm.
How to calculate logarithm with own base in Basic language?

Grzegorz
  • 3,538
  • 4
  • 29
  • 47

1 Answers1

2

There is a simple formula to calculate with any base using the natural log. The function LogBase was taken from Andrew Pitonyak's OpenOffice.org Macros Explained page 79.

Sub MyLogarithm
    MsgBox(LogBase(256,4))
End Sub

Function LogBase(x, b) As Double
    LogBase = Log(x) / Log(b)
End Function

Excel and VBA also do this: Logarithm is different using VBA and Excel function.

Community
  • 1
  • 1
Jim K
  • 12,824
  • 2
  • 22
  • 51