Content · Programming · PHP

PHP exp() Function: Usage and Examples

Learn how PHP exp works with practical examples, important behavior, relevant alternatives and common mistakes.

1 views Published Oct 16, 2026 Updated Oct 16, 2026

Calculates Euler’s number raised to the supplied exponent.

What Is exp() in PHP?

Calculates Euler’s number raised to the supplied exponent.

Its syntax is:

exp(float $num): float

Parameters:

  • $num — Accepted as float; required argument.

Return type: float. Large positive exponents overflow to INF; the result is a floating-point approximation.

Availability: Core PHP.

Example 1: Basic Usage

<?php

echo round(exp(1), 4);

Output:

2.7183

Large positive exponents overflow to INF; the result is a floating-point approximation.

Example 2: A Different Input

<?php

echo round(exp(0), 2);

Output:

1

Large positive exponents overflow to INF; the result is a floating-point approximation.

Practical Example: Applying It in a Program

<?php

$rates = [0.02, 0.05, 0.1]; foreach ($rates as $rate) { echo round(100 * exp($rate), 2) . PHP_EOL; }

Output:

102.02
105.13
110.52

Large positive exponents overflow to INF; the result is a floating-point approximation.

Important Behavior and Edge Cases

  • Key behavior: Large positive exponents overflow to INF; the result is a floating-point approximation.
  • Environment: Core PHP.

Comparison With Related Functions

FunctionPurpose
exp()Calculates Euler’s number raised to the supplied exponent.
expm1()expm1(x) computes exp(x)-1 with better precision near zero; exp(x) returns e raised to x.

Common Beginner Mistakes

MistakeCorrect Approach
Ignoring this behavior: Large positive exponents overflow to INF; the result is a floating-point approximationLarge positive exponents overflow to INF; the result is a floating-point approximation.

Key Takeaways

  • Calculates Euler’s number raised to the supplied exponent.
  • Large positive exponents overflow to INF; the result is a floating-point approximation.
  • Core PHP.

Summary: Large positive exponents overflow to INF; the result is a floating-point approximation.

Share this resourceSend this page to someone who may find it useful.