Grokking Modern System Design Interview for Engineers & Managers
Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.
The expm1()
function in D returns the mathematical $e$ raised to the power of a specific number minus 1. Here, Euler’s number, $e$, is the base of the natural logarithm.
The mathematical representation of the expm1()
function is shown below:
Note: We need to import
std.math
in our code to use theexpm1()
function. We can import it using this:import std.math
expm1(number)
// number should be float, double or real.
This function requires a number
as a parameter.
This function returns the mathematical $e$ raised to the power of number
minus 1 sent as a parameter.
Note:
- If the parameter value is positive infinity,
expm1()
returnspositive infinity
.- If the parameter value is negative infinity,
expm1()
returns-1
.- If the parameter value is
NaN
,expm1()
returnsNaN
.- If the parameter value is
-NaN
, thenexpm1()
returns-NaN
.
import core.stdc.stdio;import std.stdio;//header required for functionimport std.math;int main(){//integerwriteln ("The value of expm1(10.0) : ",expm1(10.0));//positive double valuewriteln ("The value of expm1(2.56) : ",expm1(2.56));//negative double valuewriteln ("The value of expm1(-2.56) : ",expm1(-2.56));//zerowriteln ("The value of expm1(0.0) : ",expm1(0.0));//exceptional outputswriteln ("The value of expm1(real.infinity) : ",expm1(real.infinity));writeln ("The value of expm1(-real.infinity) : ",expm1(-real.infinity));writeln ("The value of expm1(real.nan) : ",expm1(real.nan));writeln ("The value of expm1(-real.nan) : ",expm1(-real.nan));return 0;}
Line 4: We add the header, std.math
, required for the expm1()
function.
Line 9: We use expm1()
to calculate the integer value’s exponent minus 1.
Line 12: We use expm1()
to calculate the positive double value’s exponent minus 1.
Line 15: We use expm1()
to calculate the negative double value’s exponent minus 1.
Line 18: We use expm1()
to calculate the zero’s exponent minus 1.
Line 20–26: We use expm1()
to calculate the exceptional numbers’ exponent minus 1.
RELATED TAGS
CONTRIBUTOR
Grokking Modern System Design Interview for Engineers & Managers
Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.