What is the exp() function in D?

Overview

In D, the exp() function returns the mathematical ee raised to the power of a specific number. Here, Euler’s number ee is the base of the natural logarithm.

The mathematical representation of the exp() function is shown below.

Mathematical representation of the exp() function

Note: We need to import std.math in our code in order to use the exp() function. We can import it like this:
import std.math

Syntax

exp(number)
// number should be float, double or real.

Parameters

This function requires a number as a parameter.

Return value

This function returns the mathematical ee raised to the power of number sent as a parameter.

Note:

  • If the parameter value is positive infinity, exp() returns positive infinity.
  • If the parameter value is negative infinity, exp() returns 0.
  • If the parameter value is NaN, exp() returns NaN.
  • If the parameter value is -NaN, then exp() returns -NaN.

Example

import core.stdc.stdio;
import std.stdio;
//header required for function
import std.math;
int main()
{
//integer
writeln ("The value of exp(10.0) : ",exp(10.0));
//positive double value
writeln ("The value of exp(2.56) : ",exp(2.56));
//negative double value
writeln ("The value of exp(-2.56) : ",exp(-2.56));
//zero
writeln ("The value of exp(0.0) : ",exp(0.0));
//exceptional outputs
writeln ("The value of exp(real.infinity) : ",exp(real.infinity));
writeln ("The value of exp(-real.infinity) : ",exp(-real.infinity));
writeln ("The value of exp(real.nan) : ",exp(real.nan));
writeln ("The value of exp(-real.nan) : ",exp(-real.nan));
return 0;
}

Explanation

  • Line 4: We add the header std.math required for the exp() function.

  • Line 9: We use exp() to calculate the exponent of the integer value.

  • Line 12: We use exp() to calculate the exponent of the positive double value.

  • Line 15: We use exp() to calculate the exponent of the negative double value.

  • Line 18: We use exp() to calculate the exponent of the zero.

  • Line 20–26: We use exp() to calculate the exponent of exceptional numbers.

New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources