exp() function in PHP

The exp() function in PHP returns ex, where e is the mathematical constant (approximately 2.718282) raised to the power of x. This function is commonly used in mathematical calculations involving exponential growth, logarithms, and scientific computations.

Syntax

exp(x)

Parameters

  • x − A numeric value representing the exponent. Can be integer, float, or any numeric expression.

Return Value

Returns a float value representing e raised to the power of x (ex). If the result is too large to represent as a float, the function returns INF (infinity).

Basic Examples

Here are some basic examples demonstrating the exp() function ?

<?php
    echo "exp(0) = " . exp(0) . "<br>";
    echo "exp(1) = " . exp(1) . "<br>";
    echo "exp(2) = " . exp(2) . "<br>";
?>
exp(0) = 1
exp(1) = 2.718281828459
exp(2) = 7.3890560989307

Working with Different Values

The function works with both positive and negative numbers, as well as decimal values ?

<?php
    echo "exp(-1) = " . exp(-1) . "<br>";
    echo "exp(0.5) = " . exp(0.5) . "<br>";
    echo "exp(10) = " . exp(10) . "<br>";
    echo "exp(-2.5) = " . exp(-2.5) . "<br>";
?>
exp(-1) = 0.36787944117144
exp(0.5) = 1.6487212707001
exp(10) = 22026.465794807
exp(-2.5) = 0.082084998623899

Mathematical Properties

Input Result Mathematical Meaning
exp(0) 1 e0 = 1
exp(1) ? 2.718282 e1 = e
exp(-?) 0 e-? = 0
exp(?) INF e? = ?

Conclusion

The exp() function is essential for exponential calculations in PHP. It accepts any numeric value and returns e raised to that power, making it useful for mathematical modeling, compound interest calculations, and scientific applications.

Updated on: 2026-03-15T07:27:07+05:30

137 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements