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

lround.c « math « mingwex « mingw « winsup - cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7ee50df90ed0978390c538934032b42003194264 (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
lround (double x)
{
  /* Add +/- 0.5 then then round towards zero.  */
  double tmp = trunc (x + (x >= 0.0 ?  0.5 : -0.5));
  if (!isfinite (tmp) 
      || tmp > (double)LONG_MAX
      || tmp < (double)LONG_MIN)
    { 
      errno = ERANGE;
      /* Undefined behaviour, so we could return anything.  */
      /* return tmp > 0.0 ? LONG_MAX : LONG_MIN;  */
    }
  return (long)tmp;
}