- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
lrint() and llrint() in C++
In this section we will see the lrint() and llring() in C++. At first let us discuss about the lrint().
The lrint() function is used to round the fractional given value in the argument to an integral value using current rounding mode. The current mode is determined by using fesetround().>=
This lrint() function takes the double or float or integer value as input parameter, and returns the long int value by rounding the fractional part into an integral part.
Example
#include <cfenv> #include <cmath> #include <iostream> using namespace std; main() { int x = 40; long int res; fesetround(FE_DOWNWARD); // setting rounding direction to DOWNWARD as downward res = lrint(x); cout << "Downward rounding of " << x << " is " << res << endl; }
Output
Downward rounding of 40.0235 is 40
The llrint() function is used to round the fractional given value in the argument to an integral value using current rounding mode. The current mode is determined by using fesetround().
This lrint() function takes the double or float or integer value as input parameter, and returns the long long int value by rounding the fractional part into an integral part.
Example
#include <cfenv> #include <cmath> #include <iostream> using namespace std; main(){ double a; long int res; fesetround(FE_UPWARD); //set rounding direction to upward a = 40.3; res = llrint(a); cout << "Upward rounding of " << a << " is " << res << endl; fesetround(FE_DOWNWARD); //set rounding direction to downward a = 40.88; res = llrint(a); cout << "Downward rounding of " << a << " is " << res << endl; }
Output
Upward rounding of 40.3 is 41 Downward rounding of 40.88 is 40