PHP
downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

log> <log10
Last updated: Fri, 19 Jun 2009

view this page in

log1p

(PHP 4 >= 4.1.0, PHP 5)

log1p Devuelve log(1 + numero), computado en una forma que es precisa incluso cuando el valor del número es cercano a cero

Descripción

float log1p ( float $numero )
Warning

Esta función es EXPERIMENTAL. Esto significa que el comportamiento de esta función, el nombre de esta función y en definitiva TODO lo documentado sobre esta función, puede cambiar en una futura version de PHP SIN AVISO. La advertencia queda hecha, y utilizar esta extensión queda bajo su propia responsabilidad.

log1p() devuelve log(1 + numero ), computado de forma tal que el resultado es preciso incluso cuando el valor de numero es cercano a cero. log() puede devolver solo log(1) en este caso debido a la pérdida de precisión.

Note: Esta función no está implementada en plataformas Windows.

Lista de parámetros

numero

El argumento a procesar

Valores retornados

log(1 + numero )

Ver también

  • expm1() - Devuelve exp(numero) - 1, computado de una forma que es precisa incluso cuando el valor del número es cercano a cero
  • log() - Logaritmo natural
  • log10() - Logaritmo en base-10



add a note add a note User Contributed Notes
log1p
11-Sep-2002 09:29
Note that the benefit of this function for small argument values is lost if PHP is compiled against a C library that that not have builtin support for the log1p() function.

In this case, log1p() will be compiled by using log() instead, and the precision of the result will be identical to log(1), i.e. it will always be 0 for small numbers.
Sample log1p(1.0e-20):
- returns 0.0 if log1p() is approximated by using log()
- returns something very near from 1.0e-20, if log1p() is supported by the underlying C library.

One way to support log1p() correctly on any platform, so that the magnitude of the expected result is respected:

function log1p($x) {
return ($x>-1.0e-8 && $x<1.0e-8) ? ($x - $x*$x/2) : log(1+$x);
}

If you want better precision, you may use a better limited development, for small positive or negative values of x:

log(1+x) = x - x^2/2 + x^3/3 - ... + (-1)^(n-1)*x^n/n + ...

(This serial sum converges only for values of x in [0 ... 1] inclusive, and the ^ operator in the above formula means the exponentiation operator, not the PHP xor operation)

Note that log1p() is undefined for arguments lower than or equal to -1, and that the implied base of the log function is the Neperian "e" constant.

log> <log10
Last updated: Fri, 19 Jun 2009
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites