Log# ( float# )
Parameters
| float - the number to take the natural logarithm of; should be greater than zero |
Description
|
Returns the natural logarithm of a number. Log is the inverse of Exp: if x = Exp( y ) then y = Log( x ). Its base is e, roughly 2.71828. Logarithms squash a huge range of numbers into a comfortable one, which is handy whenever a game value spans several orders of magnitude. Experience-point curves, damage scaling that must not run away, audio volume sliders that sound linear to the ear, and difficulty ramps all behave better on a log scale than a straight one. The input must be greater than zero. Log( 0 ) returns negative infinity and negative input returns NaN (not a number), so guard the value before calling. If you want logarithms in base 10 - handy for counting digits or decibels - use Log10 instead. See also: Exp, Log10, Sqr. |
Example
; Log Example ; ----------- ; Log returns the NATURAL logarithm (base e) - the inverse of Exp. ; It answers: to what power must e be raised to give this value? Print "Log(1) = "+Log(1) Print "Log(2.7182818) = "+Log(2.7182818)+" (e itself, so the answer is 1)" Print "Log(100) = "+Log(100) Print "" ; Log undoes Exp Print "Exp(3) = "+Exp(3) Print "Log(Exp(3)) = "+Log(Exp(3)) Print "" ; Divide by Log(base) to get a logarithm in any other base Print "Log base 2 of 1024 = Log(1024)/Log(2) = "+(Log(1024)/Log(2)) Print "" Print "Press any key to close the example" WaitKey End
Index