Math Llrint Function - C++ Programming Tutorial
C++ Course / Math Functions / Math Llrint Function

Math Llrint Function

BLUF: Mastering Math Llrint Function is a critical step in becoming a proficient C++ developer. This lesson provides a deep dive into the syntax, performance considerations, and real-world applications of this concept.
Key Performance Insight: Math Llrint Function

C++ is renowned for its efficiency. Learn how Math Llrint Function enables low-level control and high-performance computing in the tutorial below.

C++ Math llrint

The function will round the provided value based on the current rounding mode and output a value of type long long int.

Syntax

Suppose a number is 'x'. Syntax would be:

Example

long long int llrint(data_type x);

Parameter

x : The value which is to be rounded.

Return value

It provides the integer value closest to 'x' after rounding, and the return type of the value is long long int.

Example 1

Let's examine a straightforward illustration where the rounding direction is upward.

Example

#include <iostream>
#include<math.h>
#include<cfenv>
using namespace std;
int main()
{
   float x=5.3;
   std::cout << "Value of x is :" << x<<std::endl;
   fesetround(FE_UPWARD);
   cout<<"Rounded value of x is :"<<llrint(x);
    return 0;
}

Output:

Output

Value of x is :5.3
Rounded value of x is :6

Example 2

Let's examine a basic scenario where the rounding direction is floor.

Example

#include <iostream>
#include<math.h>
#include<cfenv>
using namespace std;
int main()
{
   double x=7.9;
   std::cout << "Value of x is :" << x<<std::endl;
   fesetround(FE_DOWNWARD);
   cout<<"Rounded value of x is :"<<llrint(x);
    return 0;
}

Output:

Output

Value of x is :7.9
Rounded value of x is :7

Input Required

This code uses input(). Please provide values below:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience