log1p

(PHP 4 >= 4.1.0, PHP 5, PHP 7, PHP 8)

log1p Retorna o log(1 + numero), calculado de forma que o valor do número seja próximo de zero.

Descrição

log1p ( float $number ) : float
Aviso

Esta função é EXPERIMENTAL. O comportamento, seu nome e documentação podem mudar sem aviso em futuras versões do PHP. Utilize por sua própria conta e risco.

log1p() retorna log(1 + number) computado na forma que é correta até quando o valor de number é perto de zero. log() pode somente retornar log(1) neste caso devido a falta de precisão.

Parâmetros

number

O argumento para processar

Valor Retornado

log(1 + number)

Changelog

Versão Descrição
5.3.0 Esta função está agora disponível em todas plataformas

Veja Também

  • expm1() - Retorna exp(numero) - 1, computado de forma que é preciso mesmo quando o valor do número é perto de zero.
  • log() - Logaritmo natural
  • log10() - Logaritmo Base-10

add a note add a note

User Contributed Notes 1 note

up
2
Anonymous
21 years ago
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.
To Top