EVOLUTION-MANAGER
Edit File: Log.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Logarithms and Exponentials</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for log {base}"><tr><td>log {base}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Logarithms and Exponentials</h2> <h3>Description</h3> <p><code>log</code> computes logarithms, by default natural logarithms, <code>log10</code> computes common (i.e., base 10) logarithms, and <code>log2</code> computes binary (i.e., base 2) logarithms. The general form <code>log(x, base)</code> computes logarithms with base <code>base</code>. </p> <p><code>log1p(x)</code> computes <i>log(1+x)</i> accurately also for <i>|x| << 1</i>. </p> <p><code>exp</code> computes the exponential function. </p> <p><code>expm1(x)</code> computes <i>exp(x) - 1</i> accurately also for <i>|x| << 1</i>. </p> <h3>Usage</h3> <pre> log(x, base = exp(1)) logb(x, base = exp(1)) log10(x) log2(x) log1p(x) exp(x) expm1(x) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>x</code></td> <td> <p>a numeric or complex vector.</p> </td></tr> <tr valign="top"><td><code>base</code></td> <td> <p>a positive or complex number: the base with respect to which logarithms are computed. Defaults to <i>e</i>=<code>exp(1)</code>.</p> </td></tr> </table> <h3>Details</h3> <p>All except <code>logb</code> are generic functions: methods can be defined for them individually or via the <code><a href="groupGeneric.html">Math</a></code> group generic. </p> <p><code>log10</code> and <code>log2</code> are only convenience wrappers, but logs to bases 10 and 2 (whether computed <em>via</em> <code>log</code> or the wrappers) will be computed more efficiently and accurately where supported by the OS. Methods can be set for them individually (and otherwise methods for <code>log</code> will be used). </p> <p><code>logb</code> is a wrapper for <code>log</code> for compatibility with S. If (S3 or S4) methods are set for <code>log</code> they will be dispatched. Do not set S4 methods on <code>logb</code> itself. </p> <p>All except <code>log</code> are <a href="Primitive.html">primitive</a> functions. </p> <h3>Value</h3> <p>A vector of the same length as <code>x</code> containing the transformed values. <code>log(0)</code> gives <code>-Inf</code>, and <code>log(x)</code> for negative values of <code>x</code> is <code>NaN</code>. <code>exp(-Inf)</code> is <code>0</code>. </p> <p>For complex inputs to the log functions, the value is a complex number with imaginary part in the range <i>[-pi, pi]</i>: which end of the range is used might be platform-specific. </p> <h3>S4 methods</h3> <p><code>exp</code>, <code>expm1</code>, <code>log</code>, <code>log10</code>, <code>log2</code> and <code>log1p</code> are S4 generic and are members of the <code><a href="../../methods/html/S4groupGeneric.html">Math</a></code> group generic. </p> <p>Note that this means that the S4 generic for <code>log</code> has a signature with only one argument, <code>x</code>, but that <code>base</code> can be passed to methods (but will not be used for method selection). On the other hand, if you only set a method for the <code>Math</code> group generic then <code>base</code> argument of <code>log</code> will be ignored for your class. </p> <h3>Source</h3> <p><code>log1p</code> and <code>expm1</code> may be taken from the operating system, but if not available there then they are based on the Fortran subroutine <code>dlnrel</code> by W. Fullerton of Los Alamos Scientific Laboratory (see <a href="http://www.netlib.org/slatec/fnlib/dlnrel.f">http://www.netlib.org/slatec/fnlib/dlnrel.f</a>) and (for small x) a single Newton step for the solution of <code>log1p(y) = x</code> respectively. </p> <h3>References</h3> <p>Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) <em>The New S Language</em>. Wadsworth & Brooks/Cole. (for <code>log</code>, <code>log10</code> and <code>exp</code>.) </p> <p>Chambers, J. M. (1998) <em>Programming with Data. A Guide to the S Language</em>. Springer. (for <code>logb</code>.) </p> <h3>See Also</h3> <p><code><a href="Trig.html">Trig</a></code>, <code><a href="MathFun.html">sqrt</a></code>, <code><a href="Arithmetic.html">Arithmetic</a></code>. </p> <h3>Examples</h3> <pre> log(exp(3)) log10(1e7) # = 7 x <- 10^-(1+2*1:9) cbind(x, log(1+x), log1p(x), exp(x)-1, expm1(x)) </pre> <hr /><div style="text-align: center;">[Package <em>base</em> version 3.6.0 <a href="00Index.html">Index</a>]</div> </body></html>