Greatest Integer Function [X] indicates an integral part of the real number which is nearest and smaller integer to . It is also known as **floor of X **.

[x]=the largest integer that is less than or equal to x.

**In general**: If, <= < . Then,

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 greatest integer function is n, where n is an integer.

- 0<=x<1 will always lie in the interval [0, 0.9) so here the Greatest Integer Function of X will 0.
- 1<=x<2 will always lie in the interval [1, 1.9) so here the Greatest Integer Function of X will 1.
- 2<=x<3 will always lie in the interval [2, 2.9) so here the Greatest Integer Function of X will 2.

**Examples:**

Input: X = 2.3Output: [2.3] = 2Input: X = -8.0725Output: [-8.0725] = -9Input: X = 2Output: [2] = 2

**Number Line Representation**

If we examine a number line with the integers and plot 2.7 on it, we see:

The largest integer that is less than 2.7 is 2. So **[2.7] = 2**.

If we examine a number line with the integers and plot -1.3 on it, we see:

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 in 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 the part of the graph.

**Properties of Greatest Integer Function:**

- [X]=X holds if X is integer.
- [X+I]=[X]+I, if I is an integer then we can I separately in the Greatest Integer Function.
- [X+Y]>=[X]+[Y], means the greatest integer of sum of X and Y is equal sum of GIF of X and GIF of Y.
- If [f(X)]>=I, then f(X) >= I.
- If [f(X)]<=I, then f(X) < I+1.
- [-X]= -[X], If XInteger.
- [-X]=-[X]-1, If X is not an Integer.

It is also known as **stepwise function** or **floor **of X.

Below program shows the implementation of Greatest Integer Function using floor():

## C++

`// CPP program to illustrate ` `// greatest integer Function ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// Function to calculate the ` `// GIF value of a number ` `int` `GIF(` `float` `n) ` `{ ` ` ` `// GIF is the floor of a number ` ` ` `return` `floor` `(n); ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `int` `n = 2.3; ` ` ` ` ` `cout << GIF(n); ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java program to illustrate ` `// greatest integer Function ` ` ` `class` `GFG{ ` `// Function to calculate the ` `// GIF value of a number ` `static` `int` `GIF(` `double` `n) ` `{ ` ` ` `// GIF is the floor of a number ` ` ` `return` `(` `int` `)Math.floor(n); ` `} ` ` ` `// Driver code ` `public` `static` `void` `main(String[] args) ` `{ ` ` ` `double` `n = ` `2.3` `; ` ` ` ` ` `System.out.println(GIF(n)); ` `} ` `} ` `// This code is contributed by mits ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 program to illustrate ` `# greatest integer Function ` `import` `math ` ` ` `# Function to calculate the ` `# GIF value of a number ` `def` `GIF(n): ` ` ` ` ` `# GIF is the floor of a number ` ` ` `return` `int` `(math.floor(n)); ` ` ` `# Driver code ` `n ` `=` `2.3` `; ` ` ` `print` `(GIF(n)); ` ` ` `# This code is contributed by mits ` |

*chevron_right*

*filter_none*

## C#

`// C# program to illustrate ` `// greatest integer Function ` `using` `System; ` ` ` `class` `GFG{ ` `// Function to calculate the ` `// GIF value of a number ` `static` `int` `GIF(` `double` `n) ` `{ ` ` ` `// GIF is the floor of a number ` ` ` `return` `(` `int` `)Math.Floor(n); ` `} ` ` ` `// Driver code ` `static` `void` `Main() ` `{ ` ` ` `double` `n = 2.3; ` ` ` ` ` `Console.WriteLine(GIF(n)); ` `} ` `} ` ` ` `// This code is contributed by mits ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` ` ` `// PHP program to illustrate ` `// greatest integer Function ` ` ` ` ` `// Function to calculate the ` `// GIF value of a number ` `function` `GIF(` `$n` `) ` `{ ` ` ` `// GIF is the floor of a number ` ` ` `return` `floor` `(` `$n` `); ` `} ` ` ` `// Driver code ` ` ` `$n` `= 2.3; ` ` ` ` ` `echo` `GIF(` `$n` `); ` ` ` `?> ` |

*chevron_right*

*filter_none*

**Output:**

2

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the **DSA Self Paced Course** at a student-friendly price and become industry ready.

## Recommended Posts:

- Discrete logarithm (Find an integer k such that a^k is congruent modulo b)
- Convert a String to Integer Array in C/C++
- Count pairs in Array whose product is a Kth power of any positive integer
- Determine whether the given integer N is a Peculiar Number or not
- Euler's Totient Function
- Euler's Totient function for all numbers smaller than or equal to n
- Optimized Euler Totient Function for Multiple Evaluations
- atanh() function in C++ STL
- Program for Mobius Function
- Find ceil of a/b without using ceil() function
- atan2() function in C++ STL
- acosh() function in C++ STL
- sinh() function in C++ STL
- cosh() function in C++ STL
- tanh() function in C++ STL
- asinh() function in C++ STL
- scalbln() function in C++ STL
- logb() function in C++ STL
- ilogb() function in C++ STL
- lldiv() function in C++ STL

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.