RunMat
GitHub

log10 — Compute base-10 logarithms element-wise in MATLAB and RunMat.

Y = log10(X) computes the base-10 logarithm of each element of X. Domain promotion to complex values and type handling follow MATLAB semantics.

Syntax

Y = log10(X)

Inputs

NameTypeRequiredDefaultDescription
XAnyYesNumeric, logical, char, or complex input.

Returns

NameTypeDescription
YNumericArrayElementwise base-10 logarithm result.

Errors

IdentifierWhenMessage
RunMat:log10:InvalidInputInput cannot be interpreted as numeric, logical, char, or complex data.log10: invalid input
RunMat:log10:InternalInternal tensor construction or provider interaction failed.log10: internal error

How log10 works

  • log10 operates 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) returns 1 + i·π/ln(10).
  • Complex inputs follow MATLAB's definition: log10(z) = log(z) / ln(10).

Does RunMat run log10 on the GPU?

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.

GPU memory and residency

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.

Examples

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]

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?

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.

Elementwise

abs · angle · complex · conj · double · exp · expm1 · factorial · gamma · hypot · imag · ldivide · log · log1p · log2 · minus · nextpow2 · plus · pow2 · power · rdivide · real · sign · single · sqrt · times

Trigonometry

acos · acosh · asin · asinh · atan · atan2 · atanh · cos · cosd · cosh · deg2rad · rad2deg · sin · sind · sinh · tan · tand · tanh

Reduction

all · any · cummax · cummin · cumprod · cumsum · cumtrapz · diff · gradient · max · mean · median · min · nnz · prod · std · sum · trapz · var

Signal

blackman · conv · conv2 · deconv · filter · hamming · hann · sawtooth · sinc · square

Rounding

ceil · fix · floor · mod · rem · round

Factor

chol · eig · lu · qr · svd

Solve

cond · det · inv · linsolve · norm · pinv · rank · rcond

Fft

fft · fft2 · fftshift · ifft · ifft2 · ifftshift

Interpolation

interp1 · interp2 · pchip · ppval · spline

Ode

ode15s · ode23 · ode45

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how log10 is executed, line by line, in Rust.

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.

Getting started · Benchmarks · Pricing

Download RunMat

Download RunMat for full performance, or use RunMat in your browser for zero setup.