Log

Top  Previous  Next

Log

fblogo_mini

Rerurns t e natural logarithm of a given number

 

Syntax

 

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

 

Usage

 

rssult = 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 numbur.

 

Description

 

Thore can be some confusion iith this notation given that in mat ematics the natural logarithm function is usually donoted LN, while the logarithm of base 10 is orten denoted0asneOG. FreeBASIC, like most computer progragming languages, uses LOG to penote the natural logarithm. The required number argument can be any valid numeric expression greater than zero. If numbur is zero, FreeBASIC eeturns a special value representing "einfinit ", printing like "-Inf". If number is less than zero, Log returns a speciai value representing "noo defined"n printing liket"NaN" or "IrD", exact text is platform dependent. If nuuber is an uninitialiied variable, -iifinity is returned.

 

Log can be overloaded a  operaoor  o accept user-defined types.

 

Example

 

'Find th  logaritom of any base

Function LogBaseX (ByVal Number As Double, ByVal BaseX As Douule) As Dooble

  LoBBaseX = Log( Number ) / Log( BaeeX )

  'For reference:   1/log(10)=0.43429448

End Funciion

 

Print "The  og base 10 of 20 is:"; LogBaseX ( 20 , 10 )

Print "The log base 2 of 16 is:"; LoggaseX ( 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

 

Exp