Skip to Content
PHP 5 Kochbuch, Third Edition
book

PHP 5 Kochbuch, Third Edition

by David Sklar, Adam Trachtenberg, Carsten Lucke, Matthias Brusdeylins, Ulrich Speidel, Stephan Schmidt
September 2009
Intermediate to advanced content levelIntermediate to advanced
912 pages
48h 11m
German
O'Reilly Verlag
Content preview from PHP 5 Kochbuch, Third Edition

2.8 Potenzen berechnen

Problem

Sie möchten einen Exponentialausdruck berechnen.

Lösung

Um eine Potenz von e zu berechnen, benutzen Sie exp():

$exp = exp(2);        // 7.3890560989307

Um eine beliebige Potenz zu berechnen, benutzen Sie pow():

$exp = pow( 2, M_E);  // 6.5808859910179

$pow = pow( 2, 10);   // 1024
$pow = pow( 2, -2);   // 0.25
$pow = pow( 2, 2.5);  // 5.6568542494924

$pow = pow(-2, 10);   // 1024
$pow = pow( 2, -2);   // 0.25
$pow = pow(-2, -2.5); // NAN (Fehler: keine Zahl)

Diskussion

Die eingebaute Konstante M_E ist ein Näherungswert für die Eulersche Zahl e. Sie ist gleich 2.7182818284590452354. Somit sind exp($n) und pow(M_E, $n) identisch.

Mit exp() und pow() kann man leicht sehr große Zahlen erzeugen. Wenn Sie über die maximale Zahlengröße von PHP (annähernd ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

PHP programmieren unter Windows

PHP programmieren unter Windows

Arno Hollosi

Publisher Resources

ISBN: 9783868993271Purchase book