blob: 985a5cb4d157c16e3fceaac25075fdd580a6f07d [file] [log] [blame]
/**
* This file has no copyright assigned and is placed in the Public Domain.
* This file is part of the w64 mingw-runtime package.
* No warranty is given; refer to the file DISCLAIMER within this package.
*/
#include <math.h>
#include <limits.h>
#include <errno.h>
long long
llroundf (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_LONG_MAX
|| tmp < (float)LONG_LONG_MIN)
{
errno = ERANGE;
/* Undefined behaviour, so we could return anything. */
/* return tmp > 0.0F ? LONG_LONG_MAX : LONG_LONG_MIN; */
}
return (long long)tmp;
}