Log()

From TinyMUX
Jump to navigation Jump to search

Description

FUNCTION: 20px-Function.png log(number)

Returns the result of taking the common logarithm (base 10) of number. number may be a floating point number, and a floating point result is returned.

Related Topics: e(), exp(), ln(), power().

Examples

> say log(0)
You say "-Inf"
> say log(1)
You say "0"
> say log(10)
You say "1"
> say log(e())
You say "0.434294"


(--Soylent 01:39, 3 December 2005 (EST))

Nifty Trick

It's not really a trick, but a well known math formula. Namely, the change of base formula:

            log X
log_b X =  -------
            log b

Or more generally:

            log_c X
log_b X =  ---------
            log_c B

where c is a new sane value.

For example, if I wanted to know how many bits a certain value will take:

th ceil(fdiv(log(value),log(2)))


PennMUSH's log() takes an optional second argument that is used as the base. Internally, it uses the above formula.