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