View Discussion Show
Improve Article Save Article View Discussion Improve Article Save Article In mathematics and computer science, the floor and ceiling functions map a real number to the greatest preceding or the least succeeding integer, respectively. floor(x) : Returns the largest integer that is smaller than or equal to x (i.e : rounds downs the nearest integer). // Here x is the floating point value. // Returns the largest integer smaller // than or equal to x double floor(double x) Examples of Floor: Input : 2.5 Output : 2 Input : -2.1 Output : -3 Input : 2.9 Output : 2 CPP
Output: Floor is : 2 Floor is : -3 ceil(x) : Returns the smallest integer that is greater than or equal to x (i.e : rounds up the nearest integer). // Here x is the floating point value. // Returns the smallest integer greater // than or equal to x double ceiling(double x) Examples of Ceil: Input : 2.5 Output : 3 Input : -2.1 Output : -2 Input : 2.9 Output : 3 CPP
Ceil is : 3 Ceil is : -2 Time Complexity: O(1) Auxiliary Space: O(1) Let us see the differences in a tabular form -:
This article is contributed by Sahil Rajput. If you like GeeksforGeeks and would like to contribute, you can also write an article using write.geeksforgeeks.org or mail your article to . See your article appearing on the GeeksforGeeks main page and help other Geeks. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above. The greatest integer function is also known as the step function. It rounds up the number to the nearest integer less than or equal to the given number. The greatest integer function has a step curve which we will explore in the following sections. The domain of the greatest integer function is ℝ and its range is ℤ. Therefore the greatest integer function is simply rounding off the given number to the greatest integer that is less than or equal to the given number. Here we shall learn more about the greatest integer function, its graph, and its properties. What is Greatest Integer Function?Greatest Integer Function is a function that gives the greatest integer less than or equal to a given number. The greatest integer less than or equal to a number x is represented as ⌊x⌋. We will round off the given number to the nearest integer that is less than or equal to the number itself. Mathematically, the greatest integer function ⌊x⌋ can be defined as follows:
For example, ⌊3.02⌋ = 3, as 3 ≤ 3.02 < 4. Clearly, the input variable x can take on any real value. However, the output will always be an integer. Also, all integers will occur in the output set. Domain and Range of Greatest Integer FunctionThe greatest integer function has the domain of the function as the set of all real numbers (ℝ), while its range is the set of all integers (ℤ). Let us understand the domain and range of the function by observing the following examples of the greatest integer function in the following table:
Here, the values of x can be any real number, and hence the domain of the greatest integer function is ℝ. But observe that all the values of f(x) (y-values) are integers and hence the range is ℤ. Greatest Integer Function GraphThe greatest integer function graph is known as the step curve because of the step structure of the curve. Let us plot the greatest integer function graph. First, consider f(x) = ⌊x⌋, if x is an integer, then the value of f will be x itself. If x is a non-integer, then the value of x will be the integer just before x (on the left side of x). For example,
So for an integer n, all the numbers that lie in the interval [n, n+1) will have the value of the greatest integer function as n. The function has a constant value between any two integers. As soon as the next integer comes, the function value jumps by one unit. This means that the value of f at x = 1 is 1 (and not 0) hence there will be a hollow dot at (1, 0) and a solid dot at (1, 1) where a hollow dot means not including the value and solid dot represents including the value. These observations lead us to the following graph. From the graph above we can clearly see that inputs of the function can be any real number but the output will always be the integers. Thus, the domain of this function is real numbers (ℝ), while its range will be integers (ℤ). Greatest Integer Function PropertiesThe greatest integer function has numerous properties. Some of the important properties are listed below.
Important Notes on Greatest Integer Function: The following points are helpful to summarize the important points of the greatest integer function.
☛Related Topics: The following links are related to the greatest integer function
FAQs on Greatest Integer FunctionWhat is the Meaning of Greatest Integer Function?The greatest integer function is a function that gives the largest integer which is less than or equal to x. This function is denoted by ⌊x⌋. We will round off the given number to the nearest integer that is less than or equal to the number itself. How to Find Greatest Integer Function of a Number?The easiest way to find the greatest integer function of a number is, just plot it on the number line and select the first integer that comes on its left side. For example, ⌊4.15⌋ = 4, ⌊-4.15⌋ = -5. What is the Other Name of the Greatest Integer Function?The greatest integer function is also called a floor function. Here the function takes the lowest integral value on rounding the function value and hence it is called a floor function. Why is Greatest Integer Function Not Differentiable?As we check the graph of the greatest integer function, we can see that it is jumping whenever it reaches an integer. Since the curve is discontinuous at integers, it is not differentiable at those points. Therefore at each integer, the greatest integer function is not differentiable. How to Calculate the Greatest Integer Function of a Negative Number?Let us find the greatest integer function of -3.2. i.e., ⌊-3.2⌋. Don't think that this is equal to -3. By the definition, we have ⌊x⌋ = n, where n ≤ x < n + 1. So think which integer comes on the immediate left side of -3.2, and the answer is -4. Therefore, ⌊-3.2⌋ = -4. Is the Floor Function Differentiable?The floor function or the greatest integer function is not differentiable at integers. The floor function has jumping values at integers, so its curve is known as the step curve. The curve of floor function is discontinuous at integers and hence not differentiable at integers. What is the Domain and Range of the Greatest Integer Function?The input of the greatest integer function can be any real number whereas the greatest integer function's output is always an integer. Thus, the domain of this function is real numbers (ℝ), and its range is integers (ℤ). How to Graph Greatest Integer Function?Plotting the graph of the greatest integer function is easy. It is a step curve. Here, f(x) = ⌊x⌋, if x is an integer, then the value of f will be x itself and if x is a non-integer, then the value of x will be the integer just before x. Hence for an integer n, all the numbers of [n, n+1) will have the value of the greatest integer function as n. So for every pair of n and n + 1 on the x-axis, we get a small piece of horizontal line corresponding to y = n. But note that every horizontal line has a closed dot on the left and open dot on the right side. Which of the following functions returns the largest integer less than or equal to its argument?The method floor gives the largest integer that is less than or equal to the argument.
When a function is called by its name during the execution of a program then it is?When a function is called by its name during the execution of a program, then it is. executed.
What does the following statement mean num1 num2 Get_num ()?What does the following statement mean? num1, num2 = get_num() The function get_num() is expected to return a value each for num1 and num2. The randrange function returns a randomly selected value from a specific sequence of numbers.
What does the P in the acronym IPO refer to?An initial public offering (IPO) refers to the process of offering shares of a private corporation to the public in a new stock issuance for the first time. An IPO allows a company to raise equity capital from public investors.
|