Welcome to mirror list, hosted at ThFree Co, Russian Federation.

llroundf.c « math « mingwex « mingw « winsup - cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6a6e9b51e155efb0acba08927bf103a16f6e3caf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#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;
}