Floor of x
The floor function, denoted as ( \lfloor x \rfloor ), gives the greatest integer that is less than or equal to ( x ). In simpler terms, it rounds down the number to the nearest integer.
Java
|
|
In Java, the Math
class provides a built-in method called floor()
which takes a double
as an argument and returns the floor value as a double
. We cast it to an int
for integer representation.
C++
|
|
In C++, the <cmath>
library has a function called floor()
that works in a similar way to Java’s Math.floor()
. It returns the floor value which we cast to an int
.
Python
|
|
In Python, the math
library provides a floor()
function. No type casting is required as the function returns an integer.
Each implementation uses the language’s standard library to get the floor value of ( x ), rounding down to the nearest integer.