What does the log10 function do in MATLAB / RunMat?
Y = log10(X) computes the base-10 logarithm of every element in X, following MATLAB's
numeric semantics for real, logical, character, and complex inputs. Negative real values promote to
complex results so that you can analyze magnitudes without losing phase information.
How does the log10 function behave in MATLAB / RunMat?
log10operates element-wise with MATLAB broadcasting rules.- Logical inputs convert to doubles (
true → 1.0,false → 0.0) before the logarithm is applied. - Character arrays are interpreted as their numeric code points and return dense double tensors.
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).
log10 Function GPU Execution Behaviour
RunMat Accelerate keeps tensors on the GPU when the active provider implements unary_log10 and
the data is known to stay in the real domain. If complex outputs are required (for example, negative
inputs) or the provider lacks the hook, RunMat gathers the tensor to the host, computes the exact
MATLAB-compatible result, updates residency metadata, and returns the host-resident value.
Examples of using the log10 function in MATLAB / RunMat
Finding the order of magnitude of a number
value = log10(1000);
Expected output:
value = 3;
Computing 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 = -Inf;
Working 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];
GPU residency in RunMat (Do I need gpuArray?)
You typically do not need to call gpuArray yourself. The auto-offload planner keeps tensors on
the GPU when profitable and the result stays real. When complex results are required, RunMat
automatically gathers the data to the host to produce the precise MATLAB-compatible answer. Use
gpuArray/gather only when you want to mirror MathWorks MATLAB workflows explicitly.
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?
Current providers operate on real buffers. When complex outputs are required, RunMat gathers the tensor to the host while keeping fusion metadata consistent.
Is log10 numerically stable for very small or large values?
Yes. The implementation promotes to 64-bit doubles throughout and clamps tiny imaginary parts to zero, mirroring MATLAB's behavior for well-conditioned inputs.
See Also
log, log1p, exp, sqrt, gpuArray, gather
Source & Feedback
- The full source code for the implementation of the
log10function is available at:crates/runmat-runtime/src/builtins/math/elementwise/log10.rs - Found a bug or behavioral difference? Please open an issue with details and a minimal repro.