ceil — Round values toward positive infinity in MATLAB and RunMat.
ceil(X) rounds each element of X toward positive infinity, returning the smallest integer greater than or equal to each value. Real integer inputs preserve their exact class, shape, and values.
Syntax
Y = ceil(X)Inputs
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
X | Any | Yes | — | Numeric, logical, char, or complex input. |
Returns
| Name | Type | Description |
|---|---|---|
Y | NumericArray | Rounded output values. |
Errors
| Identifier | When | Message |
|---|---|---|
RunMat:ceil:InvalidInput | Input cannot be interpreted as numeric, logical, char, or complex data. | ceil: invalid input |
RunMat:ceil:InvalidArgument | Argument count does not match supported ceil invocation forms. | ceil: invalid argument |
RunMat:ceil:Internal | Internal tensor conversion/allocation/provider interaction failed. | ceil: internal error |
How ceil works
- Works on scalars, vectors, matrices, and higher-dimensional tensors with MATLAB broadcasting semantics.
- All eight real integer classes are exact identity operations and preserve class on host, in tables or timetables, and on supported resident providers.
- Logical inputs are promoted to doubles (
false → 0,true → 1) before applying the ceiling operation. - Character arrays are interpreted numerically (their Unicode code points) and return dense double tensors.
- Complex inputs are rounded component-wise:
ceil(a + bi) = ceil(a) + i·ceil(b). - Non-finite values (
NaN,Inf,-Inf) propagate unchanged. - Empty arrays return empty arrays of the appropriate shape.
- GPU integer input retains the same exact resident handle; floating and logical provider fallback restores output residency after host evaluation.
Does RunMat run ceil on the GPU?
When tensors already reside on the GPU, exact integer input is returned as the same resident handle because every value is already integral. Floating and logical input uses the provider unary_ceil hook when available; otherwise RunMat gathers once, applies the host operation, and re-uploads to the owning provider.
GPU memory and residency
A = gpuArray([1.8 -0.2; 2.7 3.4]);
G = ceil(A);
result = gather(G);Expected output:
result =
[ 2 0;
3 4]Examples
Rounding values up to the next integer
x = [-2.7, -0.3, 0, 0.8, 3.2];
y = ceil(x)Expected output:
y = [-2, 0, 0, 1, 4]Rounding a matrix up element-wise
A = [1.2 4.7; -3.4 5.0];
B = ceil(A)Expected output:
B = [2 5; -3 5]Rounding fractions upward in a tensor
t = reshape([-1.8, -0.2, 0.4, 1.1, 2.1, 3.6], [3, 2]);
up = ceil(t)Expected output:
up =
[-1 2;
0 3;
1 4]Rounding complex numbers toward positive infinity
z = [1.2 + 2.1i, -0.2 - 3.9i];
result = ceil(z)Expected output:
result = [2 + 3i, 0 - 3i]Keeping GPU results on-device with unary_ceil
G = gpuArray([1.8 -0.2 0.0; -1.1 2.5 -3.4]);
up = ceil(G);
gather(up)Expected output:
ans =
[ 2 0 0;
-1 3 -3]Using ceil with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how ceil changes the result.
Run a small ceil example, explain the result, then change one input and compare the output.
FAQ
Does ceil always round toward positive infinity?⌄
Yes—positive values round up away from zero, while negative values round toward zero (e.g., ceil(-0.1) = 0).
How are complex numbers handled?⌄
The real and imaginary parts are ceiled independently, matching MATLAB's component-wise definition.
What happens with logical arrays?⌄
Logical values promote to doubles (0 or 1) before rounding, so the outputs remain 0 or 1.
Can I pass character arrays to ceil?⌄
Yes. Character data is treated as its numeric code points, producing a double tensor of the same size.
Do NaN and Inf values change?⌄
No. Non-finite inputs propagate unchanged.
Will GPU execution change floating-point results?⌄
No. Providers implement IEEE-compliant ceiling; when a provider lacks unary_ceil, RunMat falls back to the CPU to preserve MATLAB-compatible behaviour.
Can fusion keep ceil on the GPU?⌄
Yes. ceil participates in elementwise fusion, so fused graphs can stay resident on the device when supported.
Related Math functions
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
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
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how ceil is executed, line by line, in Rust.
- View the source for ceil 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.