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

Run math blazing fast

GitHubX (Twitter)LinkedIn

Company

  • About
  • Pricing
  • Contact
  • License
  • Privacy

Learn

  • Docs
  • Blog
  • Benchmarks
  • RunMat vs MATLAB Online

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.

/
See all docs
Builtin Reference
    • 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

gamma — Compute gamma function values element-wise in MATLAB and RunMat.

Y = gamma(X) evaluates the Euler gamma function element-by-element for real single- or double-precision input.

Syntax

Y = gamma(X)

Inputs

NameTypeRequiredDefaultDescription
XAnyYes—Real single or double input.

Returns

NameTypeDescription
YNumericArrayGamma-function result.

Errors

IdentifierWhenMessage
RunMat:gamma:InvalidArgumentThe invocation has more than one input.gamma: invalid argument
RunMat:gamma:InvalidInputInput is not real single or double numeric data.gamma: invalid input
RunMat:gamma:InternalInternal gather, provider, or tensor construction failed.gamma: internal error

How gamma works

  • Preserves single or double precision and the input tensor shape.
  • Integer, logical, character, string, complex, and sparse inputs are rejected.
  • Returns Inf at non-positive integers, mirroring the poles in the analytic definition.
  • Keeps real-valued GPU tensors on their owning provider. If a native result does not satisfy the output contract, RunMat discards it and uses the owner-preserving host fallback.

Does RunMat run gamma on the GPU?

RunMat rejects resident integer, logical, and complex inputs before provider execution. For admitted real floating inputs, it accepts native unary_gamma output only when shape, device, real storage, precision, and owning provider match; malformed output is discarded before host fallback, and rejected non-alias allocations are freed safely before re-upload to the original owner.

GPU memory and residency

Yes. Real single- and double-precision gpuArray inputs remain associated with their owning provider whether execution uses a validated native unary_gamma result or the owner-preserving host fallback.

Examples

Converting integers to factorials automatically

gamma(5)

Expected output:

ans = 24

Evaluating half-integer inputs

gamma(0.5)

Expected output:

ans = 1.7725

Handling negative non-integers

gamma(-0.5)

Expected output:

ans = -3.5449

Applying gamma element-wise to arrays

A = [1 2; 3 4];
B = gamma(A)

Expected output:

B =
     1     1
     2     6

Using gamma with GPU tensors

G = gpuArray([0.5 1.5 2.5]);
out = gamma(G);
result = gather(out)

Expected output:

result = [1.7725 0.8862 1.3293]

Using gamma with coding agents

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

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

FAQ

How is gamma(n) related to factorials?⌄

For positive integers n, gamma(n) = (n-1)!. This identity underpins the factorial extension used throughout probability, statistics, and combinatorics.

What happens at non-positive integers?⌄

gamma has simple poles at 0, -1, -2, .... RunMat mirrors MATLAB by returning Inf at those points and signalling the singularity without throwing an error.

Are half-integers supported exactly?⌄

Yes. Values such as gamma(0.5) = sqrt(pi) are computed with a Lanczos approximation that provides double-precision accuracy consistent with MATLAB.

Do typed integer, logical, character, or complex inputs work?⌄

No. The compatibility contract accepts real single and double input only. A numeric literal such as 5 is double, so gamma(5) remains valid.

Can I keep results on the GPU?⌄

Yes. RunMat uses the owning provider's unary_gamma hook when its output satisfies the required shape, precision, storage, and ownership contract. Otherwise it computes on the host and uploads the result back to that owner.

What about overflow?⌄

Large positive inputs eventually overflow to Inf, just like MATLAB. Negative inputs near poles produce signed infinities consistent with the analytic behaviour.

Related Math functions

Elementwise

abs · angle · bsxfun · complex · conj · double · erf · erfcinv · exp · expm1 · factorial · flintmax · 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

Discrete

lcm · primes

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

  • View the source for gamma 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 gamma works
  • Does RunMat run gamma on the GPU?
  • GPU memory and residency
  • Examples
  • Converting integers to factorials automatically
  • Evaluating half-integer inputs
  • Handling negative non-integers
  • Applying gamma element-wise to arrays
  • Using gamma with GPU tensors
  • Using gamma with coding agents
  • FAQ
  • Related Math functions
  • Elementwise
  • Trigonometry
  • Reduction
  • Structure
  • Signal
  • Rounding
  • Factor
  • Solve
  • Optim
  • Ops
  • Symbolic
  • Fft
  • Interpolation
  • Discrete
  • Ode
  • Poly
  • Open-source implementation
  • About RunMat