floor() in C++
Overview
The floor in C++ is an inbuilt function that returns an integer value that is less than or equal to the argument. For example, the function floor(3.78) will return the integer value of 3 as an output. The floor in C++ is defined in the <Cmath> header file.
What is floor() in C++
In C++, the floor function returns the largest integer, which is less than or equal to the given argument. The floor in C++ is defined in the cmath header file in C++.
Example
Output
Explanation
The code discussed above passes a floating value of to the floor function as an argument. The largest integer which is less than or equal to is . Thus the floor function returns an integer value of as the output.
Syntax of the floor in C++
The syntax of the floor in C++ is as follows:
We need to pass the argument inside the function of which we want the floor value as an output. The argument can be a real number of any data type.
Parameters of the floor in C++
The floor in C++, defined in the cmath header file, takes a floating-point number whose floor value is to be computed. The parameters can be of the type:
- double
- long double
- float
Note: When an integer value is passed inside the floor function as an argument, it is type cast into a double data type.
Return Value of floor in C++
The floor in C++ returns an integer value that is less than or equal to the argument passed in the floor function.
floor for Integer Values in C++
When an integer value is passed to the floor in C++ as an argument, the return value is equal to the argument itself.
Example
Output
floor for Double and Float Values in C++
When a floating-point number is passed as an argument, the floor in C++ returns the largest integer that is less than or equal to the argument.
Example
Output
Special Cases for floor in C++
Below are some of the special cases of the in C++.
Output
Conclusion
- The is an inbuilt function in C++ that returns an integer value that is less than or equal to the argument.
- Similar to the floor in C++, the function in C++ returns an integer value greater than or equal to the argument.