Ceiling Function Calculator

Find the ceiling of any number, positive or negative, next to the floor, nearest and truncated values. Also does ceiling division, the step function a*ceil((x-h)/b)+k, and the interval of x behind a target count.

https://hexacalculator.com/calculators/mathematics/algebra/ceiling-function-calculator

Mathematics

Algebra

Ceiling Function Calculator

Find the ceiling of any number, positive or negative, next to the floor, nearest and truncated values. Also does ceiling division, the step function a*ceil((x-h)/b)+k, and the interval of x behind a target count.

Ceiling Function Calculator

Choose your task

Choose what you want to do: take the ceiling of a number, work out how many whole units cover an amount, evaluate a ceiling step function, or work backwards from a target count.

Enter your values

Only the boxes your chosen task needs are shown. The answer updates as you type.

Result

Floor of x

The whole numbers greater than or equal to 11.2 are 12, then 12 plus one, and so on. The smallest is 12, so that is the ceiling. The floor is 11 and the leftover fraction is 0.2.

See the steps

Why the ceiling function is called a step function.

Loading calculator…

The ceiling function accepts any real number and returns the smallest integer that is greater than or equal to that number. It never rounds down. So 4.2 becomes 5, and 4.9 becomes 5. On the other hand, 4 stays as 4 because it's already an integer, so it satisfies the rule.

That's the basic principle but there is a catch. A lot of people remember that "round up" means "go up", and picture a number line going from left to right, which can lead to errors when processing negative numbers. This calculator allows you to show the round up function next to rounding down, normal rounding and simple truncation so you can see where differences occur at a glance.

We also calculate the number of units which is a typical use for the ceiling function. If it's something that has to be counted as part of a unit but still counts as a full unit (e.g. crates, boards, servers, buses, pages) then the result should be rounded up and this calculation requires two numbers not just one.

The significance of the rounding function:

Formally, rounding up of a number x is the smallest integer that is greater than or equal to x.

x  =  min{nZ  :  nx}\lceil x \rceil \;=\; \min \{\, n \in \mathbb{Z} \;:\; n \ge x \,\}

This can be formulated as a question: what is the integer that is at a position greater than or equal to x? There are infinitely many such integers going off to the right; we simply take the first one.

Let's look at 11.2. All the integers that are greater than or equal to 11.2 are 12, 13, 14 and all of the integers after that. The smallest one is 12, so the ceiling of 11.2 is 12. Now let's do a negative number. All of the integers that are greater than or equal to -5 are -5, -4, -3 in this order. So the smallest one is -5, so the ceiling of -5 is -5.

This symbol is a pair of square brackets with the bottom part removed. It's a small visual pun, and the remaining part is referred to as "the ceiling". In LaTeX it is written as lceil x rceil. The domain is all real numbers, and the output is always an integer.

Examples of calculations:

The examples below are all simple and can be checked manually.

x

Ceiling of x

Why

11.2

12

12 is the first whole number at or above 11.2

4.2

5

Any decimal part at all pushes it to the next whole number

4.5

5

A half is not special here, it still goes up

7

7

Already whole, so it satisfies the rule as it stands

3.14159

4

The ceiling of pi is 4

45.12367

46

The decimals are discarded and the whole part rises by one

-5

-5

Whole numbers are left alone, negative or not

-2.3

-2

The first whole number at or above -2.3 is -2

-1.6

-1

Rounding up on a negative moves it toward zero

Comparison of rounding up, rounding down, rounding and cutting off:

There are four functions that convert a decimal number to an integer, but they are not the same function with different representations. Ceiling always rounds up toward positive infinity. Floor always rounds down toward negative infinity. Truncation simply removes the fractional part and moves the value toward zero. Rounding chooses the nearest whole number.

With positive numbers with small decimal places the three results often agree, which can lead to differences being overlooked. When negative numbers are entered, the results differ from each other.

x

Ceiling

Floor

Nearest

Toward zero

2.3

3

2

2

2

2.7

3

2

3

2

4.5

5

4

5

4

7

7

7

7

7

-2.3

-2

-3

-2

-2

-2.7

-2

-3

-3

-2

-4.5

-4

-5

-4

-4

Two rules can be derived from this table: for positive numbers, rounding up and rounding down are different for all non-integer values; for negative numbers, both methods agree for all non-integer values, and the only difference is that rounding down is called floor. The treatment of values exactly halfway between two integers is not a rule but a convention. This calculator rounds half-way values up, so -4.5 would be rounded to -4; many other calculators round half-way values towards zero, in which case -4.5 would be rounded to -5.

There are two important identities to remember: rounding up and rounding down are mirror images of each other around zero, and as long as x is not an integer they differ by exactly one.

x=xxx={0xZ1xZ\lceil x \rceil = -\left\lfloor -x \right\rfloor \qquad \lceil x \rceil - \lfloor x \rfloor = \begin{cases} 0 & x \in \mathbb{Z} \\ 1 & x \notin \mathbb{Z} \end{cases}

A wrong method that doesn't work for negative numbers

Sometimes rounding is explained by first chopping off the decimal part and then adding one. This method seems fast but actually leads to two errors.

Let's try with whole numbers: if you truncate the decimal part of 46, it remains 46 and if you add one to it, you get 47. However, rounding up 46 gives 46. Now let's try a negative number -2.3: if you truncate the decimal part, you get -2 and if you add one to it, you get -1. However, rounding up -2.3 gives -2. This method only works with positive numbers with a decimal part, which are exactly the examples that people practice most often.

A reliable method is given by definition: one asks which integer is greater than or equal to x and takes the smallest such number. If a mechanical rule is required, add one to round up instead of using the result of truncation. The addition is skipped if x is already an integer.

Rounding up on division - how many full units are needed?

This is where the power of rounding comes in. You have to cover a certain amount and delivery happens in fixed units, so anything less than one unit has to be counted as a full unit. This required quantity is the result of rounding up.

n=abcovered=n×bleft over=n×ban = \left\lceil \frac{a}{b} \right\rceil \qquad \text{covered} = n \times b \qquad \text{left over} = n \times b - a

Suppose you are using boards that are 2.5 meters long for a construction section of length 12 meters. Since 12 divided by 2.5 is equal to 4.8, you will need 5 boards. The boards can cover 12.5 meters, with the remaining 0.5 meter going into a residual waste bin. With normal rounding it would also be 5, but if you increase the length to 11 meters, rounding would require 4 boards, which in practice requires 4.4 boards, so that is 1.5 meters too short. When rounding up there can never be a shortage.

It is better to round up than to do the math in your head when it comes to mixed units. If you are using 600 millimeter thick tiles for a wall that is 2.4 meters high, then you will need to divide 2400 by 600 and round up, which gives exactly 4. If one field is set in meters and the other in millimeters, the conversion takes place before the division.

Programmers also encounter the same calculation but without floating point numbers. If a and b are positive integers, then rounding up division can be expressed with only integer operations as follows:

ab=a+b1b\left\lceil \frac{a}{b} \right\rceil = \left\lfloor \frac{a + b - 1}{b} \right\rfloor

The two formulas give the same result. The second is often used in code where high accuracy is required because it doesn't use any floating point numbers at all.

Rounding function as a step function:

If you graph the ceiling function, it looks like a staircase. Each step is horizontal and jumps up at every integer position. This is an example of a piecewise function, similar to the floor function. By stretching or shifting this staircase, we can get any general shape.

f(x)=axhb+kf(x) = a \cdot \left\lceil \frac{x - h}{b} \right\rceil + k

Parameter

What it does

Set it to 1 or 0 for

a

Height of each jump

1, a plain ceiling

b

Width of each tread

1, steps at every whole number

h

Slides the staircase right

0, no shift

k

Lifts the whole staircase

0, no shift

There are many examples of this in price calculation. For example, car parks charge 3 units per hour completed, plus an entry fee of 2 units. The price calculation function f(t) therefore multiplies the rounded-up time by 3 and then adds 2. If you park for 61 minutes, you have to pay the price for two hours. Mobile data sold in units of 500 megabytes, courier services whose prices are based on completed kilograms, and printing houses that charge per piece completed are all examples of similar but differently wide-ranging pricing models.

Backwards calculation of the result:

Sometimes you know the size you want and need to find the value of x that will give you this result. As each step is flat, the result is not a single number but always an interval.

x=n    n1<xn\lceil x \rceil = n \iff n - 1 < x \le n

The right end is inclusive and the left end is exclusive. This asymmetry is exactly what makes the ceiling function a thing. If the value is equal to n, then the ceiling is still n since n is an integer that's greater than or equal to itself. But if the value is equal to the result of n minus 1, then the ceiling is already the result of n minus 1. So the ceiling of x will only be equal to 5 if x is strictly greater than 4 and less than or equal to 5.

The same argument leads to a wider bar for units of size b.

xb=n    b(n1)<xbn\left\lceil \frac{x}{b} \right\rceil = n \iff b(n-1) < x \le b\,n

To order 5 boxes and place 12 pieces in each, the order quantity must be more than 48 (excluding this number) and no more than 60 (including this number). An additional piece requires opening a sixth box.

Rounding functions in spreadsheets and code:

Almost all programming languages provide a rounding up function, usually called ceil or something similar.

Tool

How to write it

Note

Python

math.ceil(x)

Returns a genuine int

JavaScript

Math.ceil(x)

Returns a number

SQL

CEIL(x) or CEILING(x)

Both spellings are common

Excel and Sheets

CEILING.MATH(x)

A second argument rounds up to a multiple

R

ceiling(x)

Vectorised over a whole column

C and C++

std::ceil(x)

Returns a floating point value, not an int

LaTeX

\lceil x \rceil

The bracket symbols themselves

Some hardware computers do not have this function. Some graphing calculators only offer an "int" function, which however implements rounding down. So you will search in vain for a rounding up function in the menu. The mirror identity can be helpful to solve this problem.

x=x\lceil x \rceil = -\lfloor -x \rfloor

Consider a negative number -2.3. Taking the opposite gives 2.3, and its floor is 2. Taking the opposite again gives a negative number -2, which is the ceiling of -2.3. Replace 4.2 with a value. The opposite gives a negative number -4.2, whose floor is also negative: -5. Taking the opposite again gives -5. Note: make sure your device's int actually floors and doesn't truncate towards zero. If it truncates, this method won't work for negative inputs.

Application examples for rounding up:

Capacity planning is a typical application area. The storage capacity is provided by a fixed number of hard disks, each server processes a fixed amount of load and one bus can carry a fixed number of passengers. By division and rounding up afterwards, the required quantity to be purchased is obtained.

The same principle applies to transportation and warehouse management: even if a box is not completely filled, you need a full box. A software paginates long lists with twenty entries per page. To determine how many pages are needed, the number must be divided by 20 and rounded up. Timetables and price calculations also round up to the next whole number, for example to take into account a time period that has already begun. This problem also occurs when enlarging recipes, as you cannot buy two thirds of an egg.

How to use this calculator:

Start in the menu and select the desired task. The input fields will change accordingly so that only the inputs required for this task are shown. After entering, the result is displayed.

In the roundup section, the results of rounding up are shown as a prominent heading, followed by a list of rounding down, next whole number and truncation result along with the decimal part. This is the fastest method to resolve discussions about negative numbers. In "How many full units required?" you enter the quantity and size of unit, both have a function to switch between units. The tool will give back the number of units, total covered amount and remainder. The "Step Function" calculates the general form and shows which step it is on. In "Backwards from result", you input a target quantity and the tool gives back the range of x that produces this quantity.

The bottom graph follows Mode One and Three. It plots a stairway around the entered value and shows the underlying straight line behind it so you can see how each point is raised to the upper step.

This tool is for learning and daily planning. For tasks that involve evaluation, check the definition with examples you have calculated yourself. Pay special attention to negative numbers.

Frequently asked questions

What does a rounding function do?

It replaces a number with the smallest integer that is greater than or equal to its value, i.e., it only rounds up and never down. The ceiling of 4.2 is 5, and the ceiling of 4.9 is also 5. Numbers which are already integers remain unchanged as they satisfy the rule.

What does rounding up mean for negative numbers?

Instead of moving away from zero, we're moving towards zero. So an integer that is greater than or equal to negative 2.3 would be the negative 2, the negative 1, 0 and all of the positive integers. The smallest of those is the negative 2, so the ceiling of negative 2.3 is going to be the negative 2. If we had a whole number like negative 5, then that would also be our answer. So this common "shortcut" where you just chop off the fraction and add 1 doesn't work here.

What is the rounded value of pi?

It's four. Pi is approximately 3.14159, and the integers that are greater than or equal to this value start at four, with four being the smallest of them. By similar reasoning, e is three. E is approximately 2.718, the golden ratio is two, and the golden ratio is approximately 1.618.

What is the difference between a ceiling function and a rounding function?

Rounding chooses the nearest whole number so that the result can vary in either direction. Ceiling always rounds up. For 4.2, rounding gives a result of 4 while ceiling gives a result of 5. Both functions give the same result when the number is already an integer or if the fractional part is greater than half. When you need to calculate the required number of complete units, then the correct function is ceiling because rounding may omit one unit.

If a computer only has a rounding down function, how can you implement a rounding up function?

We use the property of mirror identity. The ceiling of x is equal to the negative of the result when you floor the negative of x. You first take the opposite of the number, then you floor it and then again take the opposite of the result. So for a negative number 2.3, it becomes 2.3, by flooring it becomes 2 and then again taking the opposite which gives us -2 which is the correct answer. Make sure that your device's int function actually floors and not truncates towards zero. This method does not work with fixed size int functions if you input negative numbers.

Related calculators

Disclaimer: This calculator is provided for general informational and educational purposes only. Our calculators are under active development, and results may be inaccurate, incomplete, or unsuitable for your situation. Always verify the figures independently and seek advice from a qualified professional before relying on them. We make no warranties and accept no liability for any loss or decision arising from use of this tool.

References

  1. Wikipedia: Floor and ceiling functions

    Formal definitions, notation, identities and the graph of both step functions.

  2. Wolfram MathWorld: Ceiling Function

    Reference entry for the ceiling function, its notation and its relationship to the floor function.

  3. Python documentation: math.ceil

    The standard library definition used by most implementations of ceiling in code.

  4. Wikipedia: Rounding

    The competing conventions for turning a real number into an integer, including rounding up, down and to nearest.