Log10¶
Status: Stable
documented, exercised by the test suite and/or worked examples, with no known limitations recorded.
Description¶
Log10[z]
gives the base-10 logarithm of z, Log[10, z] = Log[z] / Log[10].
Notes
Exact powers of 10 give exact results (Log10\[1000\] = 3); a symbolic z gives Log\[z\]/Log\[10\]. Listable; maps packed arrays and compiles.Examples (11)¶
Every input below was run against the current Mathilda build and its output recorded.
Basic examples (6)¶
In[1]:= Log10[100]
Out[1]= 2
In[2]:= Log10[2.]
Out[2]= 0.30103
In[3]:= Log10[x]
Out[3]= Log[x]/Log[10]
In[4]:= Log10[1/1000]
Out[4]= -3
In[5]:= Log2[1024]
Out[5]= 10
In[6]:= Log2[{1., 2., 8.}]
Out[6]= {0.0, 1.0, 3.0}
Applications (5)¶
Powers of ten come back exact, via Log[10, z]'s power detection
Listable, so a whole list maps at once
An arbitrary-precision value routes through the MPFR logarithm
A negative real lands off the real axis, exactly as Log does
Differentiated through the Log[10, z] = Log[z]/Log[10] definition
Implementation notes¶
Algorithm. builtin_log10 is fixed_base_log(res, "Log10", 10, log10).
Log10[z] is defined, as in Mathematica, as Log[10, z] = Log[z]/Log[10]. One fast
arm handles a positive finite machine real directly with libm's log10, because
the quotient of two separately rounded logarithms is wrong by an ulp at exact
powers — log(1000.)/log(10.) is 2.9999999999999996 where log10(1000.) is
exactly 3. Every other argument — an exact power of ten (detected exactly), a
symbolic z, a negative or complex argument, an arbitrary-precision number, or
zero — is forwarded to Log[10, z], so the two spellings can never disagree.
Data structures. A single double on the fast arm; otherwise a two-argument
Log[10, z] expression handed back to the evaluator. The ND kernel
(UK_FIXED_LOG(Log10, log10, ND_LN10), registered with REG_U) maps a packed or
visible real NDArray element-wise through libm log10; a negative or complex
element escapes to clog(z)/ln(10), so exact powers of ten stay exact on the
buffer as well.
Complexity / limits. O(1) per element; Compile[] lowers it at scalar and
rank-1 shapes. Log10[0] is -Infinity and the negative real axis returns the
principal complex value, both inherited from Log.
Listable,NumericFunction,Protected, matching Mathematica.- Defined as
Log[10, z]/Log[2, z], so exact powers of the base are exact (Log10[1000] = 3,Log10[1/100] = -2,Log2[1/8] = -3) and a symbolic or non-power argument gives Mathematica'sLog[z]/Log[10]form. Zero, the negative axis, complex and arbitrary-precision arguments followLog[b, z](Log10[0] = -Infinity,Log10[0.] = Indeterminate,Log10[-1.] = 0. + 1.36438 I). - A positive machine real is evaluated with libm
log10/log2rather thanlog(z)/log(b), so an exact power stays exact:Log10[1000.]is3., not2.9999999999999996. - Fast paths. Each has an escaping NDArray kernel (libm
log10/log2on the positive axis,clog(z)/Log[b]elsewhere, promoting to complex only when an element leaves the real axis), soLog10threads over a visibleNDArray[...]and a packed real array stays packed. Both lower inCompile[](hence auto-compile) at scalar and rank-1 array shape; the scalar lowering bails to the interpreter off the positive axis.
Attributes: Listable, NumericFunction, Protected.
References¶
See also: Log2
- Source:
src/logexp.c - Specification:
docs/spec/builtins/elementary-functions.md - Tests:
tests/test_logexp.c - Tests:
tests/test_numeric.c
Notes & additional examples¶
Notes¶
Log10[z] is Log[10, z] = Log[z]/Log[10], so every rule Log knows — exact
powers, the branch cut on the negative real axis, arbitrary precision — is
inherited. The only thing Log10 adds is the dedicated libm log10 on a
positive machine real, which keeps Log10[1000.] exactly 3. where the quotient
of two rounded logarithms would land an ulp away.
The real-valued NDArray kernel maps a packed buffer element-wise and compiles
at scalar and rank-1 shapes, so Log10 in a Compile[]d body or over a packed
column runs on the buffer rather than one boxed number at a time.