Thursday, 1 August 2013

Floor and Ceiling Functions Usage



Floor and Ceiling Functions
The floor and ceiling functions give you the nearest integer up or down.
Example: What is the floor and ceiling of 2.31?
The Floor of 2.31 is 2
The Ceiling of 2.31 is 3
Floor and Ceiling of Integers
What if you want the floor or ceiling of a number that is already an integer?
That's easy: no change!
Example: What is 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:
Description: Floor and Ceiling function
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, etc.
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 is less than (or equal to) 2.31 is 2
Which leads to our definition:
Floor Function: the greatest integer that is less than or equal to x
Likewise for Ceiling:
Ceiling Function: the least integer that is greater than or equal to x

No comments:

Post a Comment