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 log()
function in D calculates the natural logarithm of a number.
The image below shows the mathematical representation of the log()
function:
Note: Import
std.math
in your code to use thelog()
function. We can import it like this:
import std.math
Following is the syntax for the method:
log(number)
// number should be float, double or real.
This function requires a
log()
returns the natural logarithm of the number sent as a parameter.
Note:
- If the parameter value is positive infinity, then
log()
returnspositive infinity
.- If the parameter value is NaN, or negative infinity, then
log()
returnsNaN
.- If the parameter value is -NaN, then
log()
returns-NaN
.- If the parameter value is <= 0, then
log()
returnsnegative infinity
.
The code below shows the use of the log()
function in D:
import core.stdc.stdio;import std.stdio;//header required for functionimport std.math;int main(){//integerwriteln ("The value of log(4.0) : ",log(4.0));//positive double valuewriteln ("The value of log(2.56) : ",log(2.56));//ewriteln ("The value of log(E) : ",log(E));//exceptional outputswriteln ("The value of log(-0.0) : ",log(-0.0));writeln ("The value of log(0.0) : ",log(0.0));writeln ("The value of log(real.infinity) : ",log(real.infinity));writeln ("The value of log(-real.infinity) : ",log(-real.infinity));writeln ("The value of log(real.nan) : ",log(real.nan));writeln ("The value of log(-real.nan) : ",log(-real.nan));return 0;}
Line 4: We add the header std.math
required for log()
function.
Line 9: We calculate the natural log of the integer value using log()
.
Line 12: We calculate the natural log of the positive double value using log()
.
Line 15: We calculate the natural log of the e
using log()
.
Line 18: We calculate the natural log of exceptional numbers
using log()
.
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.