~mingw-w64/mingw-w64/experimental

« back to all changes in this revision

Viewing changes to ros-privexp/mingw-w64-crt/math/lroundl.c

  • Committer: NightStrike
  • Date: 2010-08-11 22:20:57 UTC
  • Revision ID: svn-v4:4407c894-4637-0410-b4f5-ada5f102cad1:experimental:3266
Branch for adding option for supporting ros

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * This file has no copyright assigned and is placed in the Public Domain.
 
3
 * This file is part of the w64 mingw-runtime package.
 
4
 * No warranty is given; refer to the file DISCLAIMER.PD within this package.
 
5
 */
 
6
#include <math.h>
 
7
#include <limits.h>
 
8
#include <errno.h>
 
9
 
 
10
long
 
11
lroundl (long double x)
 
12
{
 
13
  long double res;
 
14
 
 
15
  if (x >= 0.0L)
 
16
    {
 
17
      res = ceill (x);
 
18
      if (res - x > 0.5L)
 
19
        res -= 1.0;
 
20
    }
 
21
  else
 
22
    {
 
23
      res = ceill (-x);
 
24
      if (res + x > 0.5L)
 
25
        res -= 1.0L;
 
26
      res = -res;
 
27
    }
 
28
  if (!isfinite (res)
 
29
      || res > (long double)LONG_MAX
 
30
      || res < (long double)LONG_MIN)
 
31
    {
 
32
      errno = ERANGE;
 
33
      /* Undefined behaviour, so we could return anything.  */
 
34
      /* return res > 0.0L ? LONG_MAX : LONG_MIN;  */
 
35
    }
 
36
  return (long) res;
 
37
}