RunMat
  • Pricing
RunMat
GitHub
GitHub
DownloadSign InTry in Browser
DesktopRuntimeServer
RunMat

Run math blazing fast

GitHubX (Twitter)LinkedIn

Company

  • About
  • Pricing
  • Contact

Explore

  • RunMat for academia
  • RunMat vs MATLAB Online
  • Benchmarks

Get product updates and release notes from the RunMat team.

© 2026 Dystr · Made withfor the scientific community.

RunMat™ is a registered trademark of Dystr, Inc. MATLAB® is a registered trademark of The MathWorks, Inc. RunMat is not affiliated with, endorsed by, or sponsored by The MathWorks, Inc.

LicensePrivacy
/
See all docs
Builtin Reference
    • lcm
    • primes

lcm — Compute least common multiples for positive integer inputs.

lcm(A,B) returns the least common multiples of corresponding elements of A and B. Inputs must be real positive integer values, and the inputs must be the same size or one input must be scalar.

Syntax

L = lcm(A, B)

Inputs

NameTypeRequiredDefaultDescription
ANumericArrayYes—Real positive integer scalar, vector, or array.
BNumericArrayYes—Real positive integer scalar, vector, or array.

Returns

NameTypeDescription
LNumericArrayLeast common multiples of A and B.

Errors

IdentifierWhenMessage
RunMat:lcm:InvalidInputInputs are not real positive integer numeric values, or integer class mixing is unsupported.lcm: invalid input
RunMat:lcm:SizeMismatchInputs are neither the same size nor scalar-expandable.lcm: input sizes are not compatible
RunMat:lcm:OverflowThe least common multiple cannot be represented in the output numeric class.lcm: result overflows output type
RunMat:lcm:InternalGPU gather or tensor construction fails.lcm: internal error

How lcm works

  • Accepts exactly two inputs.
  • Inputs must contain finite, real, positive integer values.
  • Inputs must have the same size or one input must be scalar-expanded.
  • Double inputs return double results; single inputs mixed with double return single results.
  • Supported unsigned integer array inputs (uint8, uint16, and uint32) preserve their output class when paired with the same class or a double scalar.
  • Scalar signed integer and uint64 inputs preserve their scalar integer class when the result is representable.
  • Mixed integer classes are rejected, matching MATLAB's requirement that integer inputs use the same class unless paired with a double scalar.
  • Logical, complex, zero, negative, fractional, non-finite, shape-mismatched, and overflowing inputs raise errors.

Examples

Least common multiples of a double array and a scalar

A = [5 17; 10 60];
L = lcm(A,45)

Expected output:

L = [45 765; 90 180]

Preserve unsigned integer output class

A = uint16([255 511 15]);
B = uint16([15 127 1023]);
L = lcm(A,B)

Expected output:

L = uint16([255 64897 5115])

Using lcm with coding agents

Open a RunMat example with live inputs, then ask the agent to explain how lcm changes the result.

Run a small lcm example, explain the result, then change one input and compare the output.

FAQ

Does lcm support implicit expansion?⌄

RunMat supports MATLAB-compatible scalar expansion. Non-scalar inputs must have the same size.

Why does lcm reject mixed integer classes?⌄

MATLAB requires integer inputs to have the same class unless the other input is a double scalar. RunMat follows that rule to avoid silently returning the wrong integer class.

Why does lcm raise overflow errors for integer outputs?⌄

The result must fit the output class. RunMat rejects overflowing integer results instead of silently truncating them.

Related Math functions

Discrete

primes

Elementwise

abs · angle · bsxfun · complex · conj · double · erf · erfcinv · exp · expm1 · factorial · flintmax · gamma · gammaln · heaviside · hypot · idivide · imag · intmax · intmin · ldivide · log · log10 · 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

Rounding

ceil · fix · floor · mod · rem · round

Factor

chol · decomposition · eig · eigs · lu · qr · svd

Solve

cond · det · inv · linsolve · norm · null · pinv · rank · rcond · rref · vecnorm

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

Symbolic

digits · int · limit · piecewise · sym · syms · vpa

Fft

fft · fft2 · fftn · fftshift · ifft · ifft2 · ifftn · ifftshift

Interpolation

griddedInterpolant · interp1 · interp1q · interp2 · pchip · ppval · spline

Ode

ode15s · ode23 · ode45

Poly

polyder · polyfit · polyint · polyval · roots

Open-source implementation

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

  • View the source for lcm 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.

Getting started · Benchmarks · Pricing

Download RunMat

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

Download RunMatOpen Sandbox
On this page
  • Syntax
  • Inputs
  • Returns
  • Errors
  • How lcm works
  • Examples
  • Least common multiples of a double array and a scalar
  • Preserve unsigned integer output class
  • Using lcm with coding agents
  • FAQ
  • Related Math functions
  • Discrete
  • Elementwise
  • Trigonometry
  • Reduction
  • Structure
  • Signal
  • Rounding
  • Factor
  • Solve
  • Optim
  • Ops
  • Symbolic
  • Fft
  • Interpolation
  • Ode
  • Poly
  • Open-source implementation
  • About RunMat