Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C

llround — C23 mathematical function

`llround(x)` from `<math.h>` rounds to the nearest `long long int`; an exact halfway case always moves away from zero, independently of the current floating-point rounding mode.

Version: C23

Syntax

long long int llround(double x);

llround(x) from <math.h> rounds to the nearest long long int; an exact halfway case always moves away from zero, independently of the current floating-point rounding mode.

The example calls llround(2.5), llround(-2.5), and llround(2.4). Output 3 -3 2 demonstrates the halfway rule for both signs and an ordinary rounding case.

For NaN or infinity, C23 permits a domain error. If the rounded result is outside the long long range, the result is an unspecified numerical value and either a domain or range error may occur; Annex F raises FE_INVALID. The function does not saturate and does not obey fesetround; validate finiteness and range before converting untrusted data.

Examples

#include <math.h>
#include <stdio.h>
int main(void){printf("%lld %lld %lld\n",llround(2.5),llround(-2.5),llround(2.4));return 0;}

Result

3 -3 2

The example calls `llround(2.5)`, `llround(-2.5)`, and `llround(2.4)`. Output `3 -3 2` demonstrates the halfway rule for both signs and an ordinary rounding case.

Sources