Help Center
Help CenterFreeBASIC

Logfunction

Returns the natural logarithm of a given number

Mathematical Functionsfunctiondocumented

Syntax

Declare Function Log cdecl ( ByVal number As Double ) As Double

Parameters

NameDescription
numberThe 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.

Remarks

Usage


result = Log( number )

Differences from QB


  • None

See also


Example


'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

Reference

  • Documented in KeyPgLog.html