Logarithms
Base.log2
— Functionlog2(x)
Compute the logarithm of x
to base 2. Throws DomainError
for negative Real
arguments.
See also: exp2
, ldexp
, ispow2
.
Examples
julia> log2(4)
2.0
julia> log2(10)
3.321928094887362
julia> log2(-2)
ERROR: DomainError with -2.0:
log2 was called with a negative real argument but will only return a complex result if called with a complex argument. Try log2(Complex(x)).
Stacktrace:
[1] throw_complex_domainerror(f::Symbol, x::Float64) at ./math.jl:31
[...]
julia> log2.(2.0 .^ (-1:1))
3-element Vector{Float64}:
-1.0
0.0
1.0
Base.log10
— Functionlog10(x)
Compute the logarithm of x
to base 10. Throws DomainError
for negative Real
arguments.
Examples
julia> log10(100)
2.0
julia> log10(2)
0.3010299956639812
julia> log10(-2)
ERROR: DomainError with -2.0:
log10 was called with a negative real argument but will only return a complex result if called with a complex argument. Try log10(Complex(x)).
Stacktrace:
[1] throw_complex_domainerror(f::Symbol, x::Float64) at ./math.jl:31
[...]
Base.log1p
— Functionlog1p(x)
Accurate natural logarithm of 1+x
. Throws DomainError
for Real
arguments less than -1.
Examples
julia> log1p(-0.5)
-0.6931471805599453
julia> log1p(0)
0.0
julia> log1p(-2)
ERROR: DomainError with -2.0:
log1p was called with a real argument < -1 but will only return a complex result if called with a complex argument. Try log1p(Complex(x)).
Stacktrace:
[1] throw_complex_domainerror(::Symbol, ::Float64) at ./math.jl:31
[...]