2002-07-29 11:00:10 +08:00
|
|
|
#include <math.h>
|
2004-04-22 12:38:24 +08:00
|
|
|
#include <limits.h>
|
|
|
|
#include <errno.h>
|
2002-06-13 18:20:48 +08:00
|
|
|
|
2002-07-29 11:00:10 +08:00
|
|
|
long
|
2004-04-22 12:38:24 +08:00
|
|
|
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;
|
|
|
|
}
|