Calculate logarithm of a value in Julia – log(), log10(), log1p() and log2() Methods
Last Updated :
26 Mar, 2020
The log()
is an inbuilt function in julia which is used to compute the natural logarithm of the specified value or throw domain error for the parameter of negative Real value.
Syntax: log(x)
Parameters:
Returns: It returns the natural logarithm of the specified value or throw domain error for the parameter of negative Real value.
Example:
println(log( 1 ))
println(log( 30 ))
println(log( 0 ))
println(log( - 44 ))
|
Output:
0.0
3.4011973816621555
-Inf
ERROR: LoadError: DomainError:
log will only return a complex result if called with a complex argument. Try log(complex(x)).
Stacktrace:
[1] nan_dom_err at ./math.jl:300 [inlined]
[2] log at ./math.jl:419 [inlined]
[3] log(::Int64) at ./math.jl:421
while loading /home/cg/root/9093667/main.jl, in expression starting on line 11
log10()
The log10()
is an inbuilt function in julia which is used to compute the logarithm of the specified value to base 10 or throw domain error for the parameter of negative Real value.
Syntax: log10(x)
Parameters:
Returns: It returns the logarithm of the specified value to base 10 or throw domain error for the parameter of negative Real value.
Example:
println(log10( 1 ))
println(log10( 10 ))
println(log10( 0 ))
println(log10( - 44 ))
|
Output:
0.0
1.0
-Inf
ERROR: LoadError: DomainError:
log10 will only return a complex result if called with a complex argument. Try log10(complex(x)).
Stacktrace:
[1] nan_dom_err at ./math.jl:300 [inlined]
[2] log10 at ./math.jl:419 [inlined]
[3] log10(::Int64) at ./math.jl:421
while loading /home/cg/root/9093667/main.jl, in expression starting on line 11
log1p()
The log1p()
is an inbuilt function in julia which is used to calculate accurate natural logarithm of 1+x, where x is the specified value and throws DomainError for Real arguments less than -1.
Syntax: log1p(x)
Parameters:
Returns: It returns the accurate natural logarithm of 1+x, where x is the specified value and throws DomainError for Real arguments less than -1.
Example:
println(log1p( 1 ))
println(log1p( 10 ))
println(log1p( 0 ))
println(log1p( - 44 ))
|
Output:
0.6931471805599453
2.3978952727983707
0.0
ERROR: LoadError: DomainError:
Stacktrace:
[1] nan_dom_err at ./math.jl:300 [inlined]
[2] log1p at ./math.jl:419 [inlined]
[3] log1p(::Int64) at ./math.jl:421
while loading /home/cg/root/9093667/main.jl, in expression starting on line 12
log2()
The log2()
is an inbuilt function in julia which is used to calculate the logarithm of x to base 2, where x is the specified value or throws DomainError for negative Real arguments.
Syntax: log2(x)
Parameters:
Returns: It returns the logarithm of x to base 2, where x is the specified value or throws DomainError for negative Real arguments.
Example:
println(log2( 1 ))
println(log2( 2 ))
println(log2( 0 ))
println(log2( - 44 ))
|
Output:
0.0
1.0
-Inf
ERROR: LoadError: DomainError:
while loading /home/cg/root/9093667/main.jl, in expression starting on line 12
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...