PHP Velho Oeste 2024

expm1

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

expm1 Berechnet exp(Zahl) - 1 mit guter Genauigkeit, auch wenn Zahl nahe bei Null liegt

Beschreibung

expm1(float $num): float

expm1() gibt das Äquivalent zu exp($num) - 1 zurück, das so berechnet wird, dass es auch dann genau ist, wenn num sehr nahe bei Null liegt. In solchen Fällen würde exp() auf Grund mangelnder Präzision gerundet eins zurückgeben und das Gesamtergebnis von exp($num) - 1 wäre einfach Null.

Parameter-Liste

num

Der zu verarbeitende Wert.

Rückgabewerte

e hoch num minus eins.

Siehe auch

  • log1p() - Berechnet log(1 + Zahl) mit guter Genauigkeit, auch wenn Zahl nahe bei Null liegt
  • exp() - Berechnet den Exponenten von e

add a note add a note

User Contributed Notes 2 notes

up
-1
brettz9 AAT yah
15 years ago
Note that exp(x)-1 can be approximated by x + x^2/2! + ... + x^n/n!  and for any value
up
-1
hagen at von-eitzen dot de
21 years ago
Compare this to log1p (which is its inverse).

Also, You may have to use a similar workaraound in case the underlying C library
does not support expm1:

<?php
function expm1($x) {
     return (
$x>-1.0e-6 && $x<1.0e-6) ? ($x + $x*$x/2) : (exp($x)-1);
}
?>
To Top