This site is supported by donations to The OEIS Foundation.

Template:Log b

From OeisWiki
Jump to: navigation, search

The {{log_b}} mathematical function template returns the base logarithm of , where and are positive real numbers.

Usage

{{log_b|a positive real number|a positive real number distinct from 1 (base)}}

or

{{log_b|a positive real number|base = a positive real number distinct from 1 (base)}}

Valid input

A positive real number as first argument, a positive real number distinct from 1 as second argument (base).

Examples

Examples with valid input

Code Result
{{log_b|0.5|2}} -1
{{log_b|1|3}} 0
{{log_b|1.5|base = 1.5}} 1
{{log_b|256|4}} 4
{{log_b|216|6}} 3
{{log_b|216|1/6}} -3
{{log_b|512|8}} 3
{{log_b|10^40|100}} 20
{{log_b|e^pi|e}} 3.1415926535898
{{log_b|pi^e|pi}} 2.718281828459
{{log_b|10^15|base = {{Golden ratio}}}} 71.774579501725
{{log_b|{{Golden ratio}}-1|base = {{Golden ratio}}}} -0.99999999999998
{{log_b|{{Golden ratio}}+1|base = {{Golden ratio}}}} 2


Examples with invalid input (returns an error message)

Code Result
{{log_b|9|-3}} Log_b error: Second argument (base) must be a positive real number distinct from 1
{{log_b|9|0}} Log_b error: Second argument (base) must be a positive real number distinct from 1
{{log_b|9|1}} Log_b error: Second argument (base) must be a positive real number distinct from 1
{{log_b|i|3}} Log_b error: First argument must be a positive real number
{{log_b|-1|3}} Log_b error: First argument must be a positive real number
{{log_b|0|3}} Log_b error: First argument must be a positive real number

Code

{{ifnum| {{{1|not a number}}}
| {{#ifexpr: ({{{1}}}) > 0
  | {{ifnum| {{{base|{{{2|not a number}}}}}}
    | {{#ifexpr: ( ({{{base|{{{2}}}}}}) > 0 ) and ( ({{{base|{{{2}}}}}}) != 1 )
      | {{#expr: ln ({{{1}}}) / ln ({{{base|{{{2}}}}}}) }}
      | {{error| Log_b error: Second argument (base) must be a positive real number distinct from 1 }}
      }}
    | {{error| Log_b error: Second argument (base) must be a positive real number distinct from 1 }}
    }}
  | {{error| Log_b error: First argument must be a positive real number }}
  }}
| {{error| Log_b error: First argument must be a positive real number }}
}}

See also