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

primes — Return prime numbers less than or equal to a scalar bound in MATLAB and RunMat.

primes(n) returns a 1-by-N row vector containing every prime number less than or equal to scalar real integer n. Values below 2 return an empty 1-by-0 row vector.

Syntax

p = primes(n)

Inputs

NameTypeRequiredDefaultDescription
nNumericScalarYes—Scalar real integer upper bound.

Returns

NameTypeDescription
pNumericArrayRow vector of prime numbers less than or equal to n.

Errors

IdentifierWhenMessage
RunMat:primes:InvalidInputInput is not a scalar real integer value.primes: invalid input
RunMat:primes:LimitRequested sieve would exceed RunMat's safety limit.primes: requested limit is too large
RunMat:primes:InternalInternal tensor construction or GPU gather failed.primes: internal error

How primes works

  • n must be a scalar, finite, real integer value.
  • Double scalar inputs return a double row vector.
  • Single and supported unsigned integer tensor/scalar inputs preserve their output dtype (single, uint8, uint16, or uint32).
  • Signed integer and uint64 scalar bounds are accepted and return a double row vector until RunMat tensors include signed integer and uint64 array storage.
  • Logical, complex, non-scalar, non-finite, and fractional inputs raise an error.
  • Requests above RunMat's bounded sieve safety limit are rejected before allocation.

Examples

Prime numbers less than or equal to 25

p = primes(25)

Expected output:

p = [2 3 5 7 11 13 17 19 23]

Prime numbers less than or equal to an unsigned integer

p = primes(uint16(12))

Expected output:

p = uint16([2 3 5 7 11])

No prime numbers below two

p = primes(1)

Expected output:

p = 1x0 empty double row vector

Using primes with coding agents

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

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

FAQ

Does primes accept arrays?⌄

No. MATLAB defines n as a scalar upper bound, and RunMat rejects non-scalar inputs.

Why does RunMat reject very large values of n?⌄

The implementation uses a host sieve and rejects requests above its safety limit before allocation to avoid unbounded memory use.

Does primes keep integer output classes?⌄

RunMat preserves supported unsigned integer tensor classes. Signed integer and uint64 array classes are not yet represented by RunMat tensors, so those scalar bounds are accepted and returned as double row vectors for compatibility with common MATLAB call sites.

Related Math functions

Discrete

lcm

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 primes is executed, line by line, in Rust.

  • View the source for primes 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 primes works
  • Examples
  • Prime numbers less than or equal to 25
  • Prime numbers less than or equal to an unsigned integer
  • No prime numbers below two
  • Using primes 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