Ln()

From TinyMUX
Jump to navigation Jump to search

Description

FUNCTION: ln(number)

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

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

Examples

> say ln(0)
You say "-Inf"
> say ln(1)
You say "0"
> say ln(e())
You say "1"
> say ln(10)
You say "2.302585"


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

Nifty Trick

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

            ln X
log_b X =  ------
            ln 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(ln(value),ln(2)))