newlib/winsup/mingw/mingwex/math/llroundl.c
Danny Smith 1a4b7623f4 * mingwex/math/lround.c: Rewrite.
* mingwex/math/lroundf.c: Rewrite.
	* mingwex/math/lroundl.c: Rewrite.
	* mingwex/math/llround.c: Rewrite.
	* mingwex/math/llroundf.c: Rewrite.
	* mingwex/math/llroundl.c: Rewrite.
2004-04-22 04:38:24 +00:00

20 lines
500 B
C

#include <math.h>
#include <limits.h>
#include <errno.h>
long long
llroundl (long double x)
{
/* Add +/- 0.5, then round towards zero. */
long double tmp = truncl (x + (x >= 0.0L ? 0.5L : -0.5L));
if (!isfinite (tmp)
|| tmp > (long double)LONG_LONG_MAX
|| tmp < (long double)LONG_LONG_MIN)
{
errno = ERANGE;
/* Undefined behaviour, so we could return anything. */
/* return tmp > 0.0L ? LONG_LONG_MAX : LONG_LONG_MIN; */
}
return (long long)tmp;
}