Open In App

Calculate logarithm of a value in Julia – log(), log10(), log1p() and log2() Methods

Last Updated : 26 Mar, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

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:

  • x: Specified values.

Returns: It returns the natural logarithm of the specified value or throw domain error for the parameter of negative Real value.

Example:




# Julia program to illustrate 
# the use of log() method
  
# Getting natural logarithm of the
# specified value or throw domain
# error for the parameter of 
# negative Real value.
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:

  • x: Specified values.

Returns: It returns the logarithm of the specified value to base 10 or throw domain error for the parameter of negative Real value.

Example:




# Julia program to illustrate 
# the use of log10() method
  
# Getting the logarithm of the
# specified value to base 10 or
# throw domain error for the 
# parameter of negative Real value.
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:

  • x: Specified values.

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:




# Julia program to illustrate 
# the use of log1p() method
  
# Getting the accurate natural 
# logarithm of 1 + x, where x is 
# the specified value and throws 
# DomainError for Real arguments
# less than -1.
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:

  • x: Specified values.

Returns: It returns the logarithm of x to base 2, where x is the specified value or throws DomainError for negative Real arguments.

Example:




# Julia program to illustrate 
# the use of log2() method
  
# Getting the logarithm of x 
# to base 2, where x is the 
# specified value or throws 
# DomainError for negative 
# Real arguments.
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
Previous
Next
Share your thoughts in the comments

Similar Reads