Standards / Extensions | C or C++ | Dependencies |
---|---|---|
C99 |
both | z/OS V1R7 |
#define _ISOC99_SOURCE
#include <math.h>
long long int llround(double x);
long long int llroundf(float x);
long long int llroundl(long double x);
#define _TR1_C99
#include <math.h>
long long int llround(float x);
long long int llround(long double x);
Function | Hex | IEEE |
---|---|---|
llround | X | X |
llroundf | X | X |
llroundl | X | X |
If successful, they return the rounded integer. If the correct value is positive or negative and too large to represent as a long long, a domain error will occur and an unspecified value is returned.
/*
* This program illustrates the use of llround() function
*
*/
#define _ISOC99_SOURCE
#include <math.h>
#include <_Ieee754.h> /* fpc functions */
#include <stdio.h>
void main() {
_FP_fpcreg_t save_rmode;
long long int rnd2nearest;
double number;
printf("Illustrates the llround() function\n\n");
save_rmode.rmode = _RMODE_RZ;
__fpc_sm(save_rmode.rmode); /* set rounding mode to round to zero */
number=501.1;
rnd2nearest = llround(number);
printf ("llround(%.1f) = %lli\n",number, rnd2nearest);
number=1.5;
rnd2nearest = llround(number);
printf ("llround(%.1f) = %lli\n",number, rnd2nearest);
number=-2.5;
rnd2nearest = llround(number);
printf ("llround(%.1f) = %lli\n",number, rnd2nearest);
}
Output
Illustrates the llround() function
llround(501.1) = 501
llround(1.5) = 2
llround(-2.5) = -3