| 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 rint 3 2026-02-08 "Linux man-pages 6.18" |
| 8 |
.SH NAME |
| 9 |
nearbyint, nearbyintf, nearbyintl, rint, rintf, rintl \- round |
| 10 |
to nearest integer |
| 11 |
.SH LIBRARY |
| 12 |
Math library |
| 13 |
.RI ( libm ,\~ \-lm ) |
| 14 |
.SH SYNOPSIS |
| 15 |
.nf |
| 16 |
.B #include <math.h> |
| 17 |
.P |
| 18 |
.BI "double nearbyint(double " x ); |
| 19 |
.BI "float nearbyintf(float " x ); |
| 20 |
.BI "long double nearbyintl(long double " x ); |
| 21 |
.P |
| 22 |
.BI "double rint(double " x ); |
| 23 |
.BI "float rintf(float " x ); |
| 24 |
.BI "long double rintl(long double " x ); |
| 25 |
.fi |
| 26 |
.P |
| 27 |
.RS -4 |
| 28 |
Feature Test Macro Requirements for glibc (see |
| 29 |
.BR feature_test_macros (7)): |
| 30 |
.RE |
| 31 |
.P |
| 32 |
.BR nearbyint (), |
| 33 |
.BR nearbyintf (), |
| 34 |
.BR nearbyintl (): |
| 35 |
.nf |
| 36 |
_POSIX_C_SOURCE >= 200112L || _ISOC99_SOURCE |
| 37 |
.fi |
| 38 |
.P |
| 39 |
.BR rint (): |
| 40 |
.nf |
| 41 |
_ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L |
| 42 |
|| _XOPEN_SOURCE >= 500 |
| 43 |
.\" || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED |
| 44 |
|| /* Since glibc 2.19: */ _DEFAULT_SOURCE |
| 45 |
|| /* glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE |
| 46 |
.fi |
| 47 |
.P |
| 48 |
.BR rintf (), |
| 49 |
.BR rintl (): |
| 50 |
.nf |
| 51 |
_ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L |
| 52 |
|| /* Since glibc 2.19: */ _DEFAULT_SOURCE |
| 53 |
|| /* glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE |
| 54 |
.fi |
| 55 |
.SH DESCRIPTION |
| 56 |
The |
| 57 |
.BR nearbyint (), |
| 58 |
.BR nearbyintf (), |
| 59 |
and |
| 60 |
.BR nearbyintl () |
| 61 |
functions round their argument to an integer value in floating-point |
| 62 |
format, using the current rounding direction (see |
| 63 |
.BR fesetround (3)) |
| 64 |
and without raising the |
| 65 |
.I inexact |
| 66 |
exception. |
| 67 |
When the current rounding direction is to nearest, these |
| 68 |
functions round halfway cases to the even integer in accordance with |
| 69 |
IEEE-754. |
| 70 |
.P |
| 71 |
The |
| 72 |
.BR rint (), |
| 73 |
.BR rintf (), |
| 74 |
and |
| 75 |
.BR rintl () |
| 76 |
functions do the same, but will raise the |
| 77 |
.I inexact |
| 78 |
exception |
| 79 |
.RB ( FE_INEXACT , |
| 80 |
checkable via |
| 81 |
.BR fetestexcept (3)) |
| 82 |
when the result differs in value from the argument. |
| 83 |
.SH RETURN VALUE |
| 84 |
These functions return the rounded integer value. |
| 85 |
.P |
| 86 |
If |
| 87 |
.I x |
| 88 |
is integral, +0, \-0, NaN, or infinite, |
| 89 |
.I x |
| 90 |
itself is returned. |
| 91 |
.SH ERRORS |
| 92 |
No errors occur. |
| 93 |
.SH ATTRIBUTES |
| 94 |
For an explanation of the terms used in this section, see |
| 95 |
.BR attributes (7). |
| 96 |
.TS |
| 97 |
allbox; |
| 98 |
lbx lb lb |
| 99 |
l l l. |
| 100 |
Interface Attribute Value |
| 101 |
T{ |
| 102 |
.na |
| 103 |
.nh |
| 104 |
.BR nearbyint (), |
| 105 |
.BR nearbyintf (), |
| 106 |
.BR nearbyintl (), |
| 107 |
.BR rint (), |
| 108 |
.BR rintf (), |
| 109 |
.BR rintl () |
| 110 |
T} Thread safety MT-Safe |
| 111 |
.TE |
| 112 |
.SH STANDARDS |
| 113 |
C11, POSIX.1-2008. |
| 114 |
.SH HISTORY |
| 115 |
C99, POSIX.1-2001. |
| 116 |
.P |
| 117 |
SUSv2 and POSIX.1-2001 contain text about overflow (which might set |
| 118 |
.I errno |
| 119 |
to |
| 120 |
.BR ERANGE , |
| 121 |
or raise an |
| 122 |
.B FE_OVERFLOW |
| 123 |
exception). |
| 124 |
In practice, the result cannot overflow on any current machine, |
| 125 |
so this error-handling stuff was just nonsense. |
| 126 |
(More precisely, overflow can happen only when the maximum value |
| 127 |
of the exponent is smaller than the number of mantissa bits. |
| 128 |
For the IEEE-754 standard 32-bit and 64-bit floating-point numbers |
| 129 |
the maximum value of the exponent is 127 (respectively, 1023), |
| 130 |
and the number of mantissa bits |
| 131 |
including the implicit bit |
| 132 |
is 24 (respectively, 53).) |
| 133 |
This was removed in POSIX.1-2008. |
| 134 |
.P |
| 135 |
If you want to store the rounded value in an integer type, |
| 136 |
you probably want to use one of the functions described in |
| 137 |
.BR lrint (3) |
| 138 |
instead. |
| 139 |
.SH SEE ALSO |
| 140 |
.BR ceil (3), |
| 141 |
.BR floor (3), |
| 142 |
.BR lrint (3), |
| 143 |
.BR round (3), |
| 144 |
.BR trunc (3) |