Blitz3D+ Command Reference

Log10# ( float# )

Parameters

float - the number to take the base 10 logarithm of; should be greater than zero

Description

Returns the base 10 logarithm of a number.

Log10( x ) answers "10 to what power gives x". Log10( 1000 ) is 3, Log10( 100 ) is 2, Log10( 1 ) is 0.

Because it counts powers of ten it is the natural choice whenever the answer should line up with the way numbers are written. Working out how many digits a score has - so you can right-align it or size a HUD field - is a one-liner with Log10. It is also the log behind decibels, if you are scaling audio levels.

The same guard applies as for Log: the input must be greater than zero. Log10( 0 ) returns negative infinity and negatives return NaN (not a number).

See also: Log, Exp, Sqr.

Example

; Log10 Example
; -------------

; Log10 returns the base-10 logarithm - the inverse of raising 10 to
; a power. Log10(1000)=3 because 10^3=1000.

Print "Log10(1)    = "+Log10(1)
Print "Log10(10)   = "+Log10(10)
Print "Log10(1000) = "+Log10(1000)
Print "Log10(0.01) = "+Log10(0.01)

Print ""

; Handy for counting digits: Floor(Log10(n))+1 is how many digits a
; positive number has - useful for lining up a score display
score=48250
digits=Floor(Log10(score))+1
Print "Score "+score+" needs Floor(Log10("+score+"))+1 = "+digits+" digits"

Print ""
Print "Press any key to close the example"
WaitKey

End

Index