### LOG

Returns the natural logarithm of a given number

Syntax:
Usage:
result = Log( number )

Parameters:
number
The number to calculate the natural log.

Return Value:
Returns the logarithm with the base e (also know as the natural logarithm) of number.

Description:
There can be some confusion with this notation given that in mathematics the natural logarithm function is usually denoted LN, while the logarithm of base 10 is often denoted as LOG. FreeBASIC, like most computer programming languages, uses LOG to denote the natural logarithm. The required number argument can be any valid numeric expression greater than zero. If number is zero, FreeBASIC returns a special value representing "-infinity", printing like "-Inf". If number is less than zero, Log returns a special value representing "not defined", printing like "NaN" or "IND", exact text is platform dependent. If number is an uninitialized variable, -infinity is returned.

Log can be overloaded as operator to accept user-defined types.

Examples:
'Find the logarithm of any base
Function LogBaseX (ByVal Number As Double, ByVal BaseX As Double) As Double
LogBaseX = Log( Number ) / Log( BaseX )
'For reference:   1/log(10)=0.43429448
End Function

Print "The log base 10 of 20 is:"; LogBaseX ( 20 , 10 )
Print "The log base 2 of 16 is:"; LogBaseX ( 16 , 2 )

Sleep

The output would look like:
```The log base 10 of 20 is: 1.301029995663981
The log base 2 of 16 is: 4```

Differences from QB:
• None

See also:
Back to Math