log2
log2(x)
Compute the logarithm of x
to base 2. Throws DomainError
for negative Real
arguments.
Examples
-
Calculate log base 2 of a positive number:
julia> log2(8) 3.0
This example calculates the logarithm base 2 of the number 8, which is 3.
-
Calculate log base 2 of a fraction:
julia> log2(0.5) -1.0
The
log2
function can handle fractional inputs. In this example, it computes the logarithm base 2 of the fraction 0.5, which is -1. - Throw an error for negative real numbers:
julia> log2(-10.0) ERROR: DomainError with -10.0: log2 will only return a complex result if called with a complex argument. Try log2(complex(x)).
The
log2
function throws aDomainError
when called with a negative real number. It suggests usinglog2(complex(x))
if a complex result is desired.
Common mistake example:
julia> log2(-5)
ERROR: DomainError with -5:
log2 will only return a complex result if called with a complex argument. Try log2(complex(x)).
In this example, the log2
function is called with a negative integer, which results in a DomainError
. Remember that log2
is only defined for positive real numbers.
See Also
abs2, beta, binomial, ceil, cell, cross, ctranspose, ctranspose!, cummin, cumprod, cumprod!, cumsum, cumsum!, cumsum_kbn, div, divrem, eigfact, eigfact!, eigmin, eps, erf, erfc, erfcinv, erfcx, erfi, erfinv, exp, exp10, exp2, expm1, exponent, factor, factorial, factorize, floor, gcd, invmod, log, log10, log1p, log2, logspace, max, min, mod, mod1, modf, next, nextpow, nextprod, num, primes, primesmask, prod, realmin, sqrt, sum!, sumabs, sumabs!, sumabs2, sumabs2!,User Contributed Notes
Add a Note
The format of note supported is markdown, use triple backtick to start and end a code block.