C examples for math.h:nearbyint
function
<cmath> <ctgmath> <math.h>
Rounds x to an integral value, using the rounding direction specified by fegetround.
long double nearbyintl (long double x); long double nearbyint (long double x); double nearbyint (double x); float nearbyintf (float x); float nearbyint (float x); double nearbyint (T x);
Parameter | Description |
---|---|
x | Value to round. |
The value of x rounded to a nearby integral.
#include <stdio.h> #include <fenv.h> #include <math.h> int main ()/*from w ww. j av a 2 s.c om*/ { printf ( "%.1f\n", nearbyint(2.1) ); printf ( "%.1f\n", nearbyint(3.9) ); printf ( "%.1f\n", nearbyint(-2.1) ); printf ( "%.1f\n", nearbyint(-3.9) ); return 0; }