PHP expm1() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
Math

Definition

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

It gives more accurate answers than writing exp($x) - 1 when the number is very close to zero.

Syntax

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

PHP
You pass a number to expm1() and it returns e to that power, minus 1.
CallWhat it does
expm1(0)Returns 0, because exp(0) is 1 and 1 - 1 is 0.
expm1(1)Returns about 1.71828.
expm1(-1)Returns about -0.6321.

Use expm1() with tiny values such as interest rates or small probabilities, where plain subtraction loses precision.

Library declarations
PHP
expm1(float $num): float

Parameters

ParameterDescription
numRequired. The exponent that e will be raised to before 1 is subtracted.

Return Value

Return ValueDescription
floatThe value of e^num - 1.

PHP Examples

Example 1 — Simple expm1() results

Compare a few small calculations.

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

How It Works

  1. expm1(0) is exp(0) - 1, which is 1 - 1 = 0.
  2. expm1(1) is e - 1, about 1.7183.
  3. expm1(2) is e squared minus 1, about 6.3891.
  4. round() keeps the printed values neat.

Example 2 — Very large and very negative inputs

See how expm1() behaves at the extremes.

PHP
<?php
echo expm1(-1000) . PHP_EOL;
echo expm1(710) . PHP_EOL;
echo expm1(0) . PHP_EOL;

How It Works

  1. For a very negative number exp() is almost 0, so expm1() becomes almost -1.
  2. PHP prints the float -1.0 as -1.
  3. For 710 the exponential overflows, so expm1() returns INF.
  4. expm1(0) stays exactly 0 with no rounding noise.

Example 3 — Continuous growth as a percentage

Find out how much a value grows when it grows continuously at 5 percent for one year.

PHP
<?php
$rate = 0.05;
$growth = expm1($rate) * 100;

echo "Growth: " . round($growth, 2) . "%" . PHP_EOL;

How It Works

  1. With continuous growth the factor after one year is e^0.05.
  2. expm1(0.05) gives only the growth part, e^0.05 - 1, which is about 0.0513.
  3. Multiplying by 100 turns it into a percentage.
  4. Continuous growth at 5 percent ends up as about 5.13 percent, a bit more than 5.

Frequently Asked Questions

It calculates e raised to a power and subtracts 1, written as exp(x) - 1, in a more precise way.
When $x is very close to zero, exp($x) is very close to 1 and the subtraction loses digits. expm1() avoids that loss.
log1p(). It calculates log(1 + x) accurately, so log1p(expm1(x)) returns x.
It returns 0, because e to the power 0 is 1 and 1 minus 1 is 0.
Yes. If the exponent is large enough (about 710 or more) the result overflows and PHP returns INF.

Next: fdiv()

The fdiv() function divides one number by another and always returns a float, even when yo.

fdiv() 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