function
<cmath> <ctgmath>

# nearbyint

```     double nearbyint  (double x);
float nearbyintf (float x);
long double nearbyintl (long double x);
```
```     double nearbyint (double x);
float nearbyint (float x);
long double nearbyint (long double x);
Round to nearby integral value
Rounds x to an integral value, using the rounding direction specified by fegetround.

This function does not raise FE_INEXACT exceptions. See rint for an equivalent function that may do.

Header <tgmath.h> provides a type-generic macro version of this function.
Additional overloads are provided in this header (`<cmath>`) for the integral types: These overloads effectively cast x to a `double` before calculations (defined for T being any integral type).

x
Value to round.

### Return Value

The value of x rounded to a nearby integral (as a floating-point value).

### Example

 ``1234567891011121314151617181920212223`` ``````/* nearbyint example */ #include /* printf */ #include /* fegetround, FE_* */ #include /* nearbyint */ int main () { printf ("rounding using "); switch (fegetround()) { case FE_DOWNWARD: printf ("downward"); break; case FE_TONEAREST: printf ("to-nearest"); break; case FE_TOWARDZERO: printf ("toward-zero"); break; case FE_UPWARD: printf ("upward"); break; default: printf ("unknown"); } printf (" rounding:\n"); printf ( "nearbyint (2.3) = %.1f\n", nearbyint(2.3) ); printf ( "nearbyint (3.8) = %.1f\n", nearbyint(3.8) ); printf ( "nearbyint (-2.3) = %.1f\n", nearbyint(-2.3) ); printf ( "nearbyint (-3.8) = %.1f\n", nearbyint(-3.8) ); return 0; }``````

Possible output:
 ``` Rounding using to-nearest rounding: nearbyint (2.3) = 2.0 nearbyint (3.8) = 4.0 nearbyint (-2.3) = -2.0 nearbyint (-3.8) = -4.0 ```