functions of a real returning respectively the largest smaller and the smallest larger integer
{\displaystyle \lfloor x\rfloor =x-\{x\}}
{\displaystyle \lfloor x\rfloor =m}
{\displaystyle \lfloor x\rfloor }
{\displaystyle \lfloor x\rfloor \leq \lceil x\rceil ,}
In mathematics, the floor function is the function that takes as input a real number x, and gives as output the greatest integer less than or equal to x, denoted โŒŠxโŒ‹ or โ€ฆ Wikipedia
๐ŸŒ
Wikipedia
en.wikipedia.org โ€บ wiki โ€บ Floor_and_ceiling_functions
Floor and ceiling functions - Wikipedia
February 5, 2026 - For example, when x = 2.0001, โŒŠ2.0001 + 1โŒ‹ = โŒˆ2.0001โŒ‰ = 3. However, if x = 2, then โŒŠ2 + 1โŒ‹ = 3, while โŒˆ2โŒ‰ = 2. The integral part or integer part of a number (partie entiรจre in the original) was first defined in 1798 by Adrien-Marie Legendre in his proof of the Legendre's formula.
๐ŸŒ
Microsoft Support
support.microsoft.com โ€บ en-us โ€บ office โ€บ ceiling-function-0a5cd7c8-0720-4f0a-bd2c-c943e510899f
CEILING function - Microsoft Support
Returns number rounded up, away from zero, to the nearest multiple of significance. For example, if you want to avoid using pennies in your prices and your product is priced at $4.42, use the formula =CEILING(4.42,0.05) to round prices up to the nearest nickel.
๐ŸŒ
MathWorks
mathworks.com โ€บ fixed-point designer โ€บ embedded implementation โ€บ fixed-point math operations in matlab and simulink
ceilDiv - Round the result of division toward positive infinity - MATLAB
y = ceilDiv(x,d,m) returns the result of x/d rounded to the nearest multiple of m in the direction of positive infinity. The datatype of y is calculated such that the wordlength and fraction length are of a sufficient size to contain both the largest and smallest possible solutions given the ...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ dsa โ€บ find-ceil-ab-without-using-ceil-function
Find ceil of a/b without using ceil() function - GeeksforGeeks
September 20, 2022 - Given below is the illustration ... Driver function int main() { // taking input 1 int a = 4; int b = 3; int val = (a / b) + ((a % b) != 0); cout << "The ceiling value of 4/3 is " << val << endl; // example of perfect division ...
๐ŸŒ
DEV Community
dev.to โ€บ kiani0x01 โ€บ python-ceiling-division-4087
Python Ceiling Division - DEV Community
July 27, 2025 - Ceiling division isnโ€™t just a trickโ€”itโ€™s a pattern. Use it when you must ensure full coverage: you need enough slots, pages, or resources. If an exact division is acceptable, stick with //. But when a remainder means โ€œone more,โ€ ceiling division guards against missing items.
Find elsewhere
๐ŸŒ
Enterprise DNA
blog.enterprisedna.co โ€บ python-ceiling-division
Python Ceiling Division: Quick User Guide โ€“ Master Data Skills + AI
For example, 7 // 2 will return 3 because the largest integer that is smaller than or equal to 3.5 is 3. The floor division operator rounds the result down. However, you can mimic the behavior of the ceiling division using the floor division operator and some arithmetic manipulation.
๐ŸŒ
Codeforces
codeforces.com โ€บ blog โ€บ entry โ€บ 78852
Alternative approaches to ceil() - Codeforces
For the example above, int a = ... quotient a/b is in int and the decimal values are discarded (floored). a/b = 1 so ceil(a/b) = ceil(1) = 1....
๐ŸŒ
Reddit
reddit.com โ€บ r/learnprogramming โ€บ writing a ceiling function in c
r/learnprogramming on Reddit: Writing a ceiling function in C
September 18, 2013 -

I'm trying to write a function that (kind of) emulates the ceiling function in the math library, in a way that is more useful for my purposes. The code I've written is not working as expected. It should take two integer arguments, divide one by the other, and round up to the nearest integer no matter what the result is.

Ex: 2/2=1 --> answer is 1; 10/3=3.333... --> round up to 4.

This is my code:

int ceiling(int number, int value){
    float a = number/value;
    int b = number/value;
    float c = a - b;
    if(c!=0){
        b=b+1;
    }
    return b;
}

Using the examples above,

ceiling(2,2); would return 1, as expected.

ceiling(10,3); returns 3, when it should return 4.

My thought process is that if a is a float, then 10/3 should be 3.33333..., and if b is an int, then 10/3 should be 3. If c is a float, a-b should be 0.33333..., then since c!=0, ceiling should increment b and return that value. Where am I going wrong?

๐ŸŒ
IncludeHelp
includehelp.com โ€บ c โ€บ fast-ceiling-of-an-integer-division.aspx
Fast ceiling of an integer division in C / C++
#include <iostream> using namespace std; int main() { int x, y, q; cout << "Enter Dividend: "; cin >> x; cout << "Enter Divisor: "; cin >> y; q = 1 + ((x - 1) / y); cout << "Quotient: " << q; return 0; }
๐ŸŒ
AskPython
askpython.com โ€บ home โ€บ is there a ceiling equivalent of // operator in python?
Is There a Ceiling Equivalent of // Operator in Python? - AskPython
May 25, 2023 - Usually, we perform ceiling division using the floor division operator and double negation. The code below is an example of how we can achieve ceiling division using the floor division operator and double negation.
๐ŸŒ
Corporate Finance Institute
corporatefinanceinstitute.com โ€บ home โ€บ resources โ€บ ceiling function
CEILING Function - Formula, Calculate, Example, Sample
June 19, 2025 - Here 3 is n (the number of rows ... the CEILING function counts by a given multiple of n. The count shown above in column G is then divided by n, that is in this case =3. Lastly, the ISEVEN function is used to force a TRUE result ...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ dsa โ€บ floor-and-ceil-of-integer-division
Floor and Ceil of Integer Division - GeeksforGeeks
July 14, 2025 - #include <iostream> #include <vector> ... to compute ceil of a / b int ceilDiv(int a, int b) { int q = a / b; // adjust up if signs same and not divisible if ((a ^ b) > 0 && a % b != 0){ q++; } return q; } vector<int> divFloorCeil(int ...
๐ŸŒ
Stack Exchange
math.stackexchange.com โ€บ questions โ€บ 2773921 โ€บ rewrite-ceil-function-of-integer-division
modular arithmetic - Rewrite ceil function of integer division - Mathematics Stack Exchange
$\begingroup$ Okay, with the added parentheses, the expression is different but still not the same as the ceiling of $a/b$. For example, if $b=23$ and $a=22$ then $a \mod b = 22$, in which case you are saying the ceiling and floor differ by 22 (but they can only differ by at most 1).
๐ŸŒ
PKH Me
blog.pkh.me โ€บ p โ€บ 36-figuring-out-round,-floor-and-ceil-with-integer-division.html
Figuring out round, floor and ceil with integer division
The integer division is symmetrical around 0 but ceil and floor aren't, so we need a way get the sign in order to branch in one direction or another. If a and b have the same sign, then a/b is positive, otherwise it's negative. This is well expressed with a xor operator, so we will be using the sign of (a^b) (where ^ is a xor operator).
Top answer
1 of 1
7

Note that truncate (rounding towards 0) is not the same as floor (rounding towards minus infinity), and hence the oposite of truncate would always round away from zero, which is not the same as ceil (rounding towards plus infinity).

The following implements the opposite of truncate, so this is not ceil but always rounds away from 0. To get the same level of optimisation this uses several TeX primitives, which are marked as :D in expl3 (so this is evil code!).

\ExplSyntaxOn
\cs_new_eq:NN \__wamseln_sep: \tex_let:D
\cs_new_eq:NN \__wamseln_int_eval:w \tex_numexpr:D
\cs_new_eq:NN \__wamseln_int_eval_end: \tex_relax:D
\cs_new:Npn \wamseln_div_away:nn #1#2
  {
    \int_value:w \__wamseln_int_eval:w
      \exp_after:wN \__wamseln_div_away:w
        \int_value:w \__wamseln_int_eval:w #1 \exp_after:wN \__wamseln_sep:
        \int_value:w \__wamseln_int_eval:w #2 \__wamseln_sep:
    \__wamseln_int_eval_end:
  }
\cs_new:Npn \__wamseln_div_away:w #1#2\__wamseln_sep: #3#4\__wamseln_sep:
  {
    \if_meaning:w 0#1
      0
    \else:
      (
        #1#2
        \if_meaning:w -#1 - \else: + \fi:
        ( \if_meaning:w -#3 \else: #3 \fi: #4 - 1 ) / 2
      )
    \fi:
    / #3#4
  }
\NewDocumentCommand \test { m m m }
  {
    \int_compare:nNnTF { \wamseln_div_away:nn {#1} {#2} } = {#3}
      { \message{.} }
      {
        \msg_error:nneeee { wamseln } { test-failed }
          {#1} {#2} {#3} { \wamseln_div_away:nn {#1} {#2} }
      }
  }
\msg_new:nnn { wamseln } { test-failed }
  { Unit~ test~ failed!~ away((#1)/(#2))=(#3)~ but~ was~ (#4) }
\ExplSyntaxOff

\typeout{Tests:}

\test{21}{5}{5}

\test{-21}{5}{-5}

\test{21}{-5}{-5}

\test{-21}{-5}{5}

\test{2}{4}{1}

\test{-2}{4}{-1}

\test{2}{-4}{-1}

\test{-2}{-4}{1}

\stop

The most glaring optimisation this code takes is to check whether a number is positive, negative, or zero by just taking a look at the first token of the result of \numexpr.

  • Iff the number is zero the first token is 0 (and that's also the only token)
  • Iff the number is negative the first token is -
  • Else the number is positive

The fastest check in TeX is \ifx (\if_meaning:w in expl3), so it makes sense to favour it over \if_int_compare:w where possible (slowish by comparison) or even \str_case:nn (horribly slow!!!). (Please note that the aforementioned performance categories are meant in the context of low level optimisation of TeX code, none of the three mentioned options is horribly slow from a user's point of view per se, though one should avoid \str_case:nn in the inner loop of some often called procedure)

๐ŸŒ
Brilliant
brilliant.org โ€บ wiki โ€บ ceiling-function
Ceiling Function | Brilliant Math & Science Wiki
For example, \[\begin{array} &\lceil ... x \rceil.\) The ceiling is related to the floor function by the formula \[ \lceil x \rceil = -\lfloor -x \rfloor....