log10 — Compute base-10 logarithms element-wise in MATLAB and RunMat.
Y = log10(X) computes the base-10 logarithm of each floating-point element of X, including principal-branch complex promotion. Integer, logical, character, and explicit-GPU real-to-complex forms are separately gated RunMat extensions.
Syntax
Y = log10(X)Inputs
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
X | Any | Yes | — | Numeric, logical, char, or complex input. |
Returns
| Name | Type | Description |
|---|---|---|
Y | NumericArray | Elementwise base-10 logarithm result. |
Errors
| Identifier | When | Message |
|---|---|---|
RunMat:log10:InvalidInput | Input cannot be interpreted as numeric, logical, char, or complex data. | log10: invalid input |
RunMat:log10:Internal | Internal tensor construction or provider interaction failed. | log10: internal error |
How log10 works
log10operates element-wise with MATLAB broadcasting rules.- In RunMat extension mode, logical inputs convert to doubles (
true → 1.0,false → 0.0) before the logarithm is applied; compatibility mode rejects this extension. - In RunMat extension mode, character arrays are interpreted as their numeric code points and return dense double tensors; compatibility mode rejects this extension.
- Integer input is a RunMat-only extension. All eight integer classes are accepted only when every value is exactly representable in binary64, and the result is double or complex double.
log10(0)returns-Inf, matching MATLAB's handling of the logarithm singularity at zero.- Negative real values promote to complex results:
log10(-10)returns1 + i·π/ln(10). - Complex inputs follow MATLAB's definition:
log10(z) = log(z) / ln(10).
Does RunMat run log10 on the GPU?
RunMat Accelerate uses the exact owning provider's reduce_min to classify resident real data, then validates any unary_log10 output for non-aliasing, shape, device, owner, storage, and precision. When complex output or a fallback is required, it downloads through that owner, computes on the host, and restores the result to the same owner when representable while preserving provenance. log10 is intentionally excluded from fusion until fused execution can represent its complex-domain semantics.
GPU memory and residency
You typically do not need to call gpuArray yourself. RunMat resolves the exact provider that owns the input. Real data can remain resident through reduce_min and unary_log10; integer, logical, complex, unsupported-hook, and real-to-complex paths gather through that owner and restore the correctly typed result when representable. Explicit gpuArray input that requires real-to-complex promotion is a RunMat-only extension and is rejected in compatibility mode.
Examples
Finding the order of magnitude of a number
value = log10(1000)Expected output:
value = 3Computing base-10 logarithms of a matrix
A = [1 10 100; 0.1 0.01 0.001];
B = log10(A)Expected output:
B = [0 1 2; -1 -2 -3]Understanding how log10 handles zero
z = log10(0)Expected output:
z = -InfWorking with negative inputs using complex results
neg = [-10 -100];
out = log10(neg)Expected output:
out = [1.0000 + 1.3644i, 2.0000 + 1.3644i]Running log10 on GPU-resident data
G = gpuArray([1 10 1000]);
result = log10(G);
host = gather(result)Expected output:
host = [0 1 3]Using log10 with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how log10 changes the result.
Run a small log10 example, explain the result, then change one input and compare the output.
FAQ
When should I use log10 instead of log?⌄
Use log10 when you want base-10 magnitudes, such as for decibel calculations or scientific notation. Use log (natural logarithm) for exponential growth/decay or calculus contexts.
What happens if an element is zero?⌄
log10(0) returns negative infinity (-Inf), matching MATLAB behavior.
How does log10 handle negative real numbers?⌄
Negative values promote to complex numbers with an imaginary component of π/ln(10). This preserves phase information instead of producing NaN.
Can I pass complex inputs to log10?⌄
Yes. Complex scalars and tensors are handled as log(z) / ln(10), matching MATLAB exactly.
Does the GPU implementation support complex outputs?⌄
The real provider hook cannot produce complex output. RunMat gathers through the exact owner, computes the complex result on the host, and restores it to that owner when the complex class is representable. Explicit gpuArray input requiring this extension is rejected in compatibility mode.
Is log10 numerically stable for very small or large values?⌄
Double input is computed in double precision and single input preserves single precision. RunMat clamps tiny finite components created by floating-point roundoff to zero. Integer extensions enter the double domain only when exactly representable in binary64.
Related Math functions
Elementwise
abs · angle · bsxfun · complex · conj · double · erf · erfcinv · exp · expm1 · factorial · flintmax · gamma · gammaln · heaviside · hypot · idivide · imag · intmax · intmin · ldivide · log · log1p · log2 · minus · nextpow2 · plus · pow2 · power · rdivide · real · realmax · realmin · realsqrt · rescale · sign · single · sqrt · swapbytes · times · typecast · uint16 · uint32 · uint8
Trigonometry
acos · acosh · asin · asinh · atan · atan2 · atanh · cos · cosd · cosh · cospi · deg2rad · pol2cart · rad2deg · sin · sind · sinh · sinpi · tan · tand · tanh
Reduction
all · any · bounds · cummax · cummin · cumprod · cumsum · cumtrapz · diff · gradient · max · maxk · mean · median · min · mink · movmax · movmean · movmedian · movmin · movprod · movstd · movsum · movvar · nnz · prod · rms · std · sum · trapz · var
Structure
bandwidth · isdiag · ishermitian · issymmetric · istril · istriu · symrcm
Signal
blackman · butter · buttord · cheb2ord · conv · conv2 · deconv · downsample · envelope · filter · filtfilt · fir1 · freqz · gauspuls · hamming · hann · hilbert · periodogram · pulstran · pwelch · rectpuls · resample · sawtooth · sinc · spectrogram · square · tripuls · unwrap · upsample · zplane
Optim
coneprog · fminbnd · fminunc · fsolve · fzero · integral · linprog · lsqcurvefit · lsqnonlin · optimoptions · optimset · quad · secondordercone
Ops
cross · ctranspose · dot · mldivide · mpower · mrdivide · mtimes · pagemtimes · pagetranspose · trace · transpose
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how log10 is executed, line by line, in Rust.
- View the source for log10 in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 license.
- RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
- Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.