rint() is used to round of the floating-point argument to an integer value (in floating-point format). You can also determine the current rounding mode using a function fesetround() according to which the rint function returns the rounded integer value.
Syntax double rint(double x); float rint(float x); long double rint(long double x); Header file : cmath Parameters : The rint() function takes a single argument value to round. Returns : By default, the rounding direction is set to 'to-nearest' otherwise the rint() function rounds the argument to an integral value, using the rounding direction specified by fegetround() and returns the value.
Exceptions or Errors
1. If the result of the function is outside the range of the return type, a domain error error may occur.
2. If the argument is 0, it is returned unmodified.
3. If the argument is infinite, it is returned unmodified.
Input : 3.3 Output : 3 Input : 3.5 Output : 4 Input : 3.7 Output : 4
By default, the rounding direction is set to the nearest integer. But using fesetround() function, we can the direction of our choice.
fesetround(FE_DOWNWARD) fesetround(FE_UPWARD) Header file : cfenv
- If rint() function is used with argument 3.7 and fesetround(FE_DOWNWARD) is also used, the output would be 3
- If rint() function is used with argument 3.3 and fesetround(FE_UPWARD) is also used, the output would be 4
rintf() function is same as the rint function. The only difference is that the parameter and return type of the function is float type. The ‘f‘ character appended to ‘rintf‘ stands for float and it signify the parameter type and return type of the function.
Syntax : float rintf(float x);
Here, variables are assigned float type otherwise type mismatch error occurs.
rintl() function is same as the rint function.The only difference is that the parameter and return type of the function is long double type.The ‘l‘ character appended to ‘rintl‘ stands for long double and it signify the parameter type and return type of the function.
Syntax : long double rintl(long double x);
Here, variables are assigned long double type otherwise type mismatch error occurs.
- cin get() in C++ with Examples
- Difference between Increment and Decrement Operators
- Map of Vectors in C++ STL with Examples
- Problem in comparing Floating point numbers and how to compare them correctly?
- exit(0) vs exit(1) in C/C++ with Examples
- C++ program to print all Even and Odd numbers from 1 to N
- Reverse the content of a file and store it in another
- Minimum cells to be flipped to get a 2*2 submatrix with equal elements
- Nested Loops in C++ with Examples
- _Find_first() function in C++ bitset with Examples
- _Find_next() function in C++ bitset with Examples
- Left-Right traversal of all the levels of N-ary tree
- Difference between Iterators and Pointers in C/C++ with Examples
- ostream::seekp(pos) method in C++ with Exmaples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.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.