gamma — Evaluate the real Euler gamma function element by element.
gamma evaluates dense real single or double values, preserves their class and shape, and supports validated provider-resident execution.
Syntax
Y = gamma(X)Inputs
X- Type
NumericArray- Required
- Yes
- Description
- Dense real single- or double-precision input.
Returns
Y- Type
NumericArray- Description
- Real gamma-function values with the input class and shape.
Errors
RunMat:gamma:InvalidArgument- When
- The invocation does not have exactly one input.
- Message
gamma: invalid argument
RunMat:gamma:InvalidInput- When
- Input is not dense real single or double numeric data.
- Message
gamma: invalid input
RunMat:gamma:Internal- When
- Internal allocation, provider execution, gather, or residency restoration fails.
- Message
gamma: internal error
RunMat:gamma:TooManyOutputs- When
- More than one output is requested.
- Message
gamma: too many output arguments
Gamma values and poles
gamma(X) evaluates the Euler gamma function element by element. For a positive integer n, gamma(n) equals (n-1)!; gamma(0.5) equals sqrt(pi). Analytic continuation defines values for negative nonintegers, while zero and negative integers are poles.
Large positive inputs eventually overflow to infinity. The practical positive-integer thresholds are gamma(172) for double and gamma(single(36)) for single because the next values exceed their respective finite ranges.
Classes and shapes
Input must be dense, real single or double. Output preserves the input class and shape. Fixed-width integer, logical, character, string, complex, object, and sparse inputs are rejected in both compatibility modes. An ordinary whole-number literal such as 5 is double and remains valid.
Scalar, vector, matrix, N-D, and empty arrays are evaluated element by element. NaN propagates and infinities follow the real gamma limits.
Accelerated and distributed execution
A real floating provider input can use its owner's unary_gamma hook. RunMat validates shape, real storage, precision, owner, device, and non-aliasing, then restores the input's residency intent on the result. Only a typed unsupported result enters host fallback; provider failures and malformed outputs remain visible.
Fallback gathers through the exact owner, evaluates the same host algorithm, and restores the result to that owner with the original precision and residency intent. Distributed arrays use the declared partition-local unary mapping.
Examples
Relate gamma to factorial
Y = gamma(5)Expected output:
Y = 24Evaluate a half-integer
Y = gamma(0.5)Expected output:
Y = 1.7725Evaluate a negative noninteger
Y = gamma(-0.5)Expected output:
Y = -3.5449Evaluate an array element by element
X = [1 2; 3 4];
Y = gamma(X)Expected output:
Y = [1 1; 2 6]Preserve single precision
Y = gamma(single([0.5 1.5 2.5]))Expected output:
Y is a single row vectorEvaluate gamma on resident input
G = gpuArray([0.5 1.5 2.5]);
Gy = gamma(G);
Y = gather(Gy)Expected output:
Y = [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 related to factorial?⌄
For each positive integer n, gamma(n) = (n-1)!, or equivalently gamma(n+1) = factorial(n).
What happens at zero and negative integers?⌄
Those values are poles of the gamma function and produce infinities according to the real implementation's pole convention.
Does gamma accept fixed-width integers?⌄
No. Convert deliberately with double or single. An ordinary numeric literal such as 5 already has class double.
Does gamma accept complex input?⌄
No. This builtin implements the documented real single/double surface.
What precision is returned?⌄
Single input returns single; double input returns double. Shape is preserved.
Can results remain provider-resident?⌄
Yes. A valid native result remains resident, and unsupported hooks use exact-owner gather and restoration.
Related Math functions
Elementwise
abs · angle · besselj · bsxfun · complex · conj · double · eps · erf · erfcinv · exp · expm1 · flintmax · gammaln · heaviside · hypot · imag · int16 · int32 · int64 · int8 · intmax · intmin · ldivide · log · log10 · log1p · log2 · minus · nextpow2 · plus · pow2 · power · rdivide · real · realmax · realmin · realsqrt · rescale · sign · single · sqrt · times · typecast · uint16 · uint32 · uint64 · uint8
Optim
acceptancesa · annealingboltz · annealingfast · coneprog · crossoverarithmetic · crossoverheuristic · crossoverintermediate · crossoverlaplace · crossoverscattered · crossoversinglepoint · crossovertwopoint · eqnproblem · EquationProblem.solve · EquationProblem.subsasgn · EquationProblem.subsref · evaluate · fgoalattain · fitscalingprop · fitscalingrank · fitscalingshiftlinear · fitscalingtop · fminbnd · fmincon · fminimax · fminsearch · fminunc · fseminf · fsolve · fzero · ga · gacreationlinearfeasible · gacreationnonlinearfeasible · gacreationsobol · gacreationuniform · gacreationuniformint · gaplotbestf · gaplotbestindiv · gaplotdistance · gaplotexpectation · gaplotgenealogy · gaplotmaxconstr · gaplotrange · gaplotscorediversity · gaplotscores · gaplotselection · gaplotstopping · integerConstraint · integral · intlinprog · linprog · lsqcurvefit · lsqlin · LsqlinWarmStart.subsasgn · LsqlinWarmStart.subsref · lsqnonlin · lsqnonneg · mutationadaptfeasible · mutationgaussian · mutationpositivebasis · mutationpower · mutationuniform · optimexpr · optimget · OptimizationConstraint.evaluate · OptimizationConstraint.subsasgn · OptimizationConstraint.subsref · OptimizationExitflag.double · OptimizationExitflag.eq · OptimizationExitflag.ne · OptimizationExitflag.string · OptimizationExpression.acos · OptimizationExpression.acosh · OptimizationExpression.acot · OptimizationExpression.acoth · OptimizationExpression.acsc · OptimizationExpression.acsch · OptimizationExpression.asec · OptimizationExpression.asech · OptimizationExpression.asin · OptimizationExpression.asinh · OptimizationExpression.atan · OptimizationExpression.atanh · OptimizationExpression.cat · OptimizationExpression.cos · OptimizationExpression.cosh · OptimizationExpression.cot · OptimizationExpression.coth · OptimizationExpression.csc · OptimizationExpression.csch · OptimizationExpression.ctranspose · OptimizationExpression.cumprod · OptimizationExpression.cumsum · OptimizationExpression.diag · OptimizationExpression.diff · OptimizationExpression.dot · OptimizationExpression.eq · OptimizationExpression.evaluate · OptimizationExpression.exp · OptimizationExpression.ge · OptimizationExpression.horzcat · OptimizationExpression.ldivide · OptimizationExpression.le · OptimizationExpression.log · OptimizationExpression.mean · OptimizationExpression.minus · OptimizationExpression.mldivide · OptimizationExpression.mpower · OptimizationExpression.mrdivide · OptimizationExpression.mtimes · OptimizationExpression.norm · OptimizationExpression.plus · OptimizationExpression.power · OptimizationExpression.prod · OptimizationExpression.rdivide · OptimizationExpression.reshape · OptimizationExpression.sec · OptimizationExpression.sech · OptimizationExpression.sin · OptimizationExpression.sinh · OptimizationExpression.sqrt · OptimizationExpression.subsasgn · OptimizationExpression.subsref · OptimizationExpression.sum · OptimizationExpression.tan · OptimizationExpression.tanh · OptimizationExpression.times · OptimizationExpression.trace · OptimizationExpression.transpose · OptimizationExpression.uminus · OptimizationExpression.uplus · OptimizationExpression.vertcat · OptimizationExpression.zeros · OptimizationExpression.zerosLike · OptimizationProblem.solve · OptimizationProblem.subsasgn · OptimizationProblem.subsref · OptimizationVariable.subsasgn · OptimizationVariable.subsref · optimoptions · optimplotconstrviolation · optimplotfirstorderopt · optimplotfunccount · optimplotfval · optimplotfvalconstr · optimplotmilp · optimplotstepsize · optimplotx · optimproblem · optimset · optimvar · optimwarmstart · particleswarm · patternsearch · psplotbestf · psplotbestx · psplotfuncount · psplotmaxconstr · psplotmeshsize · pswcreationuniform · pswplotbestf · quad · quadprog · QuadprogWarmStart.subsasgn · QuadprogWarmStart.subsref · saplotbestf · saplotbestx · saplotf · saplotstopping · saplottemperature · saplotx · savemilpsolutions · secondordercone · selectionremainder · selectionroulette · selectionstochunif · selectiontournament · selectionuniform · simulannealbnd · solve · surrogateopt · surrogateoptplot · temperatureboltz · temperatureexp · temperaturefast
Trigonometry
acos · acosd · acosh · acotd · acscd · asecd · asin · asind · asinh · atan · atan2 · atan2d · atand · 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
Factor
chol · decomposition · decomposition.ctranspose · decomposition.mldivide · decomposition.mrdivide · decomposition.mtimes · decomposition.rdivide · decomposition.subsref · decomposition.times · decomposition.uminus · decomposition.uplus · eig · eigs · gmres · ichol · ilu · lu · ordeig · ordqz · ordschur · pcg · qr · qz · rsf2csf · schur · svd
Ops
cross · ctranspose · dot · mldivide · mpower · mrdivide · mtimes · pagemtimes · pagetranspose · trace · transpose
Interpolation
griddedInterpolant · griddedInterpolant.subsref · interp1 · interp1q · interp2 · pchip · ppval · spline
Integer Division
Source you can read
Every RunMat function's source is public. 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 a runtime that executes MATLAB-syntax code fast on any GPU. The runtime is free for individuals, including freelancers; students and faculty at an academic institution, for teaching or research there; contributors to an open-source project, for work on that project; organizations with 250 or fewer people and US$10M or less in annual revenue; and anyone, for non-production use. See runmat.com/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.