PHP Doku:: Berechent log(1 + number) mit erhöhter Genauigkeit - function.log1p.html

Verlauf / Chronik / History: (7) anzeigen

Sie sind hier:
Doku-StartseitePHP-HandbuchFunktionsreferenzMathematische ErweiterungenMathematische FunktionenMathematische Funktionenlog1p

Ein Service von Reinhard Neidl - Webprogrammierung.

Mathematische Funktionen

<<log10

log>>

log1p

(PHP 4 >= 4.1.0, PHP 5)

log1p Berechent log(1 + number) mit erhöhter Genauigkeit

Beschreibung

float log1p ( float $number )
Warnung

Diese Funktion ist EXPERIMENTELL. Das Verhalten, der Funktionsname und alles Andere, was hier dokumentiert ist, kann sich in zukünftigen PHP-Versionen ohne Ankündigung ändern. Seien Sie gewarnt und verwenden Sie diese Funktion auf eigenes Risiko.

log1p() berechnet log(1 + number) auf eine Weise die auch dann noch genaue Ergebnisse liefert wenn der Wert von number nur sehr klein ist. log() liefert in solchen Fällen auf Grund von Rundungsfehlern oft nur den Wert von log(1) und vernachlässigt die Nachkommastellen.

Parameter-Liste

number

Der zu verarbeitende Wert

Rückgabewerte

log(1 + number)

Changelog

Version Beschreibung
5.3.0 Die Funktion ist nun auf allen Plattformen verfügbar.

Siehe auch

  • expm1() - Exponentialfunktion mit erhöhter Genauigkeit
  • log() - Logarithmus
  • log10() - Dekadischer Logarithmus


Ein BenutzerBeitrag:
- Beiträge aktualisieren...

11.09.2002 11: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.



PHP Powered Diese Seite bei php.net
The PHP manual text and comments are covered by the Creative Commons Attribution 3.0 License © the PHP Documentation Group - Impressum - mail("TO:Reinhard Neidl",...)