In D, the exp()
function returns the mathematical raised to the power of a specific number. Here, Euler’s number is the base of the natural logarithm.
The mathematical representation of the exp()
function is shown below.
Note: We need to import
std.math
in our code in order to use theexp()
function. We can import it like this:import std.math
exp(number)
// number should be float, double or real.
This function requires a number
as a parameter.
This function returns the mathematical raised to the power of number
sent as a parameter.
Note:
- If the parameter value is positive infinity,
exp()
returnspositive infinity
.- If the parameter value is negative infinity,
exp()
returns0
.- If the parameter value is
NaN
,exp()
returnsNaN
.- If the parameter value is
-NaN
, thenexp()
returns-NaN
.
import core.stdc.stdio;import std.stdio;//header required for functionimport std.math;int main(){//integerwriteln ("The value of exp(10.0) : ",exp(10.0));//positive double valuewriteln ("The value of exp(2.56) : ",exp(2.56));//negative double valuewriteln ("The value of exp(-2.56) : ",exp(-2.56));//zerowriteln ("The value of exp(0.0) : ",exp(0.0));//exceptional outputswriteln ("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;}
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.