📜  在 Julia 中计算一个值的对数 - log()、log10()、log1p() 和 log2() 方法

📅  最后修改于: 2022-05-13 01:54:51.521000             🧑  作者: Mango

在 Julia 中计算一个值的对数 - log()、log10()、log1p() 和 log2() 方法

log()是 julia 中的一个内置函数,用于计算指定值的自然对数或为负 Real 值的参数抛出域错误。

例子:

# 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))

输出:

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

日志10()

log10()是 julia 中的一个内置函数,用于计算以 10 为底的指定值的对数,或为负 Real 值的参数抛出域错误。

例子:

# 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))

输出:

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()

log1p()是 julia 中的一个内置函数,用于计算 1+x 的准确自然对数,其中 x 是指定值,对于小于 -1 的实数参数抛出 DomainError。

例子:

# 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))

输出:

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

日志2()

log2()是 julia 中的内置函数,用于计算 x 以 2 为底的对数,其中 x 是指定值,或者对于负 Real 参数抛出 DomainError。

例子:

# 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))

输出:

0.0
1.0
-Inf
ERROR: LoadError: DomainError:
while loading /home/cg/root/9093667/main.jl, in expression starting on line 12