| 1 |
'\" t |
| 2 |
.\" Copyright 2001, Andries E. Brouwer <[email protected]> |
| 3 |
.\" Copyright, the authors of the Linux man-pages project |
| 4 |
.\" |
| 5 |
.\" SPDX-License-Identifier: Linux-man-pages-copyleft |
| 6 |
.\" |
| 7 |
.TH lrint 3 2026-02-08 "Linux man-pages 6.18" |
| 8 |
.SH NAME |
| 9 |
lrint, lrintf, lrintl, llrint, llrintf, llrintl \- round to nearest integer |
| 10 |
.SH LIBRARY |
| 11 |
Math library |
| 12 |
.RI ( libm ,\~ \-lm ) |
| 13 |
.SH SYNOPSIS |
| 14 |
.nf |
| 15 |
.B #include <math.h> |
| 16 |
.P |
| 17 |
.BI "long lrint(double " x ); |
| 18 |
.BI "long lrintf(float " x ); |
| 19 |
.BI "long lrintl(long double " x ); |
| 20 |
.P |
| 21 |
.BI "long long llrint(double " x ); |
| 22 |
.BI "long long llrintf(float " x ); |
| 23 |
.BI "long long llrintl(long double " x ); |
| 24 |
.fi |
| 25 |
.P |
| 26 |
.RS -4 |
| 27 |
Feature Test Macro Requirements for glibc (see |
| 28 |
.BR feature_test_macros (7)): |
| 29 |
.RE |
| 30 |
.P |
| 31 |
All functions shown above: |
| 32 |
.nf |
| 33 |
_ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L |
| 34 |
.fi |
| 35 |
.SH DESCRIPTION |
| 36 |
These functions round their argument to the nearest integer value, |
| 37 |
using the current rounding direction (see |
| 38 |
.BR fesetround (3)). |
| 39 |
.P |
| 40 |
Note that unlike the |
| 41 |
.BR rint (3) |
| 42 |
family of functions, |
| 43 |
the return type of these functions differs from |
| 44 |
that of their arguments. |
| 45 |
.SH RETURN VALUE |
| 46 |
These functions return the rounded integer value. |
| 47 |
.P |
| 48 |
If |
| 49 |
.I x |
| 50 |
is a NaN or an infinity, |
| 51 |
or the rounded value is too large to be stored in a |
| 52 |
.I long |
| 53 |
.RI ( "long long" |
| 54 |
in the case of the |
| 55 |
.B ll* |
| 56 |
functions), |
| 57 |
then a domain error occurs, and the return value is unspecified. |
| 58 |
.\" The return value is -(LONG_MAX - 1) or -(LLONG_MAX -1) |
| 59 |
.SH ERRORS |
| 60 |
See |
| 61 |
.BR math_error (7) |
| 62 |
for information on how to determine whether an error has occurred |
| 63 |
when calling these functions. |
| 64 |
.P |
| 65 |
The following errors can occur: |
| 66 |
.TP |
| 67 |
Domain error: \f[I]x\f[] is a NaN or infinite, or the rounded value is too large |
| 68 |
.\" .I errno |
| 69 |
.\" is set to |
| 70 |
.\" .BR EDOM . |
| 71 |
An invalid floating-point exception |
| 72 |
.RB ( FE_INVALID ) |
| 73 |
is raised. |
| 74 |
.P |
| 75 |
These functions do not set |
| 76 |
.IR errno . |
| 77 |
.\" FIXME . Is it intentional that these functions do not set errno? |
| 78 |
.\" Bug raised: https://www.sourceware.org/bugzilla/show_bug.cgi?id=6798 |
| 79 |
.SH ATTRIBUTES |
| 80 |
For an explanation of the terms used in this section, see |
| 81 |
.BR attributes (7). |
| 82 |
.TS |
| 83 |
allbox; |
| 84 |
lbx lb lb |
| 85 |
l l l. |
| 86 |
Interface Attribute Value |
| 87 |
T{ |
| 88 |
.na |
| 89 |
.nh |
| 90 |
.BR lrint (), |
| 91 |
.BR lrintf (), |
| 92 |
.BR lrintl (), |
| 93 |
.BR llrint (), |
| 94 |
.BR llrintf (), |
| 95 |
.BR llrintl () |
| 96 |
T} Thread safety MT-Safe |
| 97 |
.TE |
| 98 |
.SH STANDARDS |
| 99 |
C11, POSIX.1-2008. |
| 100 |
.SH HISTORY |
| 101 |
glibc 2.1. |
| 102 |
C99, POSIX.1-2001. |
| 103 |
.SH SEE ALSO |
| 104 |
.BR ceil (3), |
| 105 |
.BR floor (3), |
| 106 |
.BR lround (3), |
| 107 |
.BR nearbyint (3), |
| 108 |
.BR rint (3), |
| 109 |
.BR round (3) |