pqx9Dbm6uOE

Floor and Ceiling Functions

Sage the owl standing on a floor with a ceiling above

The floor and ceiling functions give us the nearest integer up or down.

Example: What's the floor and ceiling of 2.31?

Diagram showing 2.31 between floor 2 and ceiling 3

The Floor of 2.31 is 2
The Ceiling of 2.31 is 3

Floor and Ceiling of Integers

What if we want the floor or ceiling of a number that's already an integer?

That's easy: no change!

Example: What's the floor and ceiling of 5?

The Floor of 5 is 5
The Ceiling of 5 is 5

Here are some example values for you:

x Floor Ceiling
−1.1 −2 −1
0 0 0
1.01 1 2
2.9 2 3
3 3 3

Symbols

The symbols for floor and ceiling are like the square brackets [ ] with the top or bottom part missing:

Floor and Ceiling function symbols

But I prefer to use the word form: floor(x) and ceil(x)

Definitions

How do we give this a formal definition?

Example: How do we define the floor of 2.31?

Well, it has to be an integer ...

... and it has to be less than (or maybe equal to) 2.31, right?

  • 2 is less than 2.31 ...
  • but 1 is also less than 2.31,
  • and so is 0, and −1, −2, −3, and so on.

Oh no! There are lots of integers less than 2.31.

So which one do we choose?

Choose the greatest one (which is 2 in this case)

So we get:

The greatest integer that's less than (or equal to) 2.31 is 2

Which leads to our definitions:

Floor Function: the greatest integer that's less than or equal to x

Ceiling Function: the least integer that's greater than or equal to x

As A Graph

The Floor Function is this curious "step" function (like an infinite staircase):

Step function graph for floor(x) with solid dots on the left of each step
The Floor Function

A solid dot means "including" and an open dot means "not including".

Example: at x=2 we meet:

  • an open dot at y=1 (so it doesn't include x=2),
  • and a solid dot at y=2 (which does include x=2)

so the answer is y=2

And this is the Ceiling Function:

Ceiling function graph
The Ceiling Function

See them together here:
../algebra/images/function-graph.js?fn0=floor(x)&fn1=ceil(x)&xmin=-5&xmax=5&ymin=-3&ymax=3

The Int Function

The Int function (short for integer) is like the Floor function, BUT some calculators and computer programs show different results when given negative numbers:

So be careful with this function!

The Frac Function

With the Floor function, we "throw away" the fractional part. That part is called the frac or fractional part function:

frac(x) = x − floor(x)

It looks like a sawtooth:

Frac function graph
The Frac Function

Example: what's frac(3.65)?

frac(x) = x − floor(x)

So: frac(3.65) = 3.65 − floor(3.65) = 3.65 − 3 = 0.65

Example: what's frac(−3.65)?

frac(x) = x − floor(x)

So: frac(−3.65) = (−3.65) − floor(−3.65) = (−3.65) − (−4) = −3.65 + 4 = 0.35

BUT many calculators and computer programs use frac(x) = x − int(x), and so their result depends on how they calculate int(x):

  • Some say frac(−3.65) = 0.35 i.e −3.65 − (−4)
  • Others say frac(−3.65) = −0.65 i.e. −3.65 − (−3)

So be careful using this function with negative values.

2434, 2435, 2436, 2437, 2438, 2439