PHP exp() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
Math

Definition

The exp() function calculates e raised to the power of a number, where e is Euler's number (about 2.71828).

It is used for growth and decay formulas, compound interest and many science and statistics calculations.

Syntax

Call exp() with the values you need. Start with this line.

PHP
You pass a number to exp() and it returns e to that power as a float.
CallWhat it does
exp(1)Returns about 2.71828, which is e itself.
exp(0)Returns 1, because any number to the power of 0 is 1.
exp(-1)Returns about 0.3679, which is 1 divided by e.

exp() is the opposite of log(). In other words log(exp(x)) gives you x back.

Library declarations
PHP
exp(float $num): float

Parameters

ParameterDescription
numRequired. The exponent that e will be raised to.

Return Value

Return ValueDescription
floatThe value of e raised to the power num. It can be INF for very large inputs.

PHP Examples

Example 1 — Calculate powers of e

Find e to a few simple powers.

PHP
<?php
echo round(exp(1), 4) . PHP_EOL;
echo exp(0) . PHP_EOL;
echo round(exp(2), 4) . PHP_EOL;

How It Works

  1. exp(1) is e to the power 1, so it equals e (2.71828...).
  2. exp(0) is e to the power 0, which is always 1.
  3. exp(2) is e x e, which is about 7.3891.
  4. round(..., 4) keeps the printed numbers short.

Example 2 — Negative and overflowing values

See what happens with a negative exponent and with huge numbers.

PHP
<?php
echo round(exp(-1), 4) . PHP_EOL;
echo exp(710) . PHP_EOL;
echo exp(-1000) . PHP_EOL;

How It Works

  1. exp(-1) is 1 divided by e, about 0.3679.
  2. exp(710) is bigger than the largest float PHP can store, so it returns INF.
  3. exp(-1000) is so close to zero that it underflows to 0.
  4. PHP does not throw an error for these cases, it just returns INF or 0.

Example 3 — Continuous compound interest

Use the formula A = P x e^(r x t) to see how money grows.

PHP
<?php
$principal = 1000;
$rate = 0.05;
$years = 2;

$amount = $principal * exp($rate * $years);

echo "Amount: " . round($amount, 2) . PHP_EOL;

How It Works

  1. The principal is 1000, the yearly rate is 5 percent (0.05) and the time is 2 years.
  2. rate x years gives the exponent 0.1.
  3. exp(0.1) is about 1.10517, so the money grows by about 10.5 percent.
  4. round(..., 2) shows the final amount with two decimals like real money.

Frequently Asked Questions

It returns e raised to the power of the number you pass in. For example exp(1) is about 2.71828.
exp() always uses the base e. pow() lets you choose any base, like pow(2, 3) for 2 to the power 3.
Use log(), which is the natural logarithm. log(exp(5)) returns 5.
If the exponent is greater than about 709.78 the answer is too large for a float, so PHP returns INF.
Yes. expm1() calculates exp(x) - 1 and stays accurate when x is very close to zero.

Next: expm1()

The expm1() function returns exp(num) - 1, which means e raised to a power minus one.

expm1() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful