newlib/winsup/mingw/mingwex/math/lroundf.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
448 B
C

#include <math.h>
#include <limits.h>
#include <errno.h>
long
lroundf (float x)
{
/* Add +/- 0.5, then round towards zero. */
float tmp = truncf (x + (x >= 0.0F ? 0.5F : -0.5F));
if (!isfinite (tmp)
|| tmp > (float)LONG_MAX
|| tmp < (float)LONG_MIN)
{
errno = ERANGE;
/* Undefined behaviour, so we could return anything. */
/* return tmp > 0.0F ? LONG_MAX : LONG_MIN; */
}
return (long)tmp;
}