![]() |
VOOZH | about |
The greatest Integer Function [X] indicates an integral part of the real number which is the nearest and smaller integer to . It is also known as the floor of X.
[x]=the largest integer that is less than or equal to x.In general: If, <= < . Then,
This means if X lies in [n, n+1), then the Greatest Integer Function of X will be n.
In the above figure, we are taking the floor of the values each time. When the intervals are in the form of [n, n+1), the value of the greatest integer function is n, where n is an integer.
Examples:
Input: X = 2.3
Output: [2.3] = 2
Input: X = -8.0725
Output: [-8.0725] = -9
Input: X = 2
Output: [2] = 2
Number Line Representation
Since the largest integer that is less than -1.3 is -2, so [-1.3] = 2.
Here, f(x)=[X] could be expressed graphically as:
Note: In the above graph, the left endpoint at every step is blocked(dark dot) to show that the point is a member of the graph, and the other right endpoint (open circle) indicates the points that are not part of the graph.
Properties of Greatest Integer Function:
It is also known as the stepwise function or floor of X.
The below program shows the implementation of the Greatest Integer Function using floor() method.
2
Time Complexity: O(1)
Auxiliary Space: O(1)