]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - sysdeps/ieee754/ldbl-128ibm/s_lroundl.c
Update copyright dates with scripts/update-copyrights
[thirdparty/glibc.git] / sysdeps / ieee754 / ldbl-128ibm / s_lroundl.c
index 6c3a3140c91dd94a35f43c3140d8c98f9fda68b2..770de9710054c6c2f5abe80fd7723b56a5a36454 100644 (file)
@@ -1,6 +1,6 @@
 /* Round to long int long double floating-point values.
    IBM extended format long double version.
-   Copyright (C) 2006-2014 Free Software Foundation, Inc.
+   Copyright (C) 2006-2021 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
 
    You should have received a copy of the GNU Lesser General Public
    License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
+   <https://www.gnu.org/licenses/>.  */
 
 #include <math.h>
 #include <fenv.h>
+#include <math_private.h>
 #include <math_ldbl_opt.h>
 #include <float.h>
 #include <ieee754.h>
@@ -80,7 +81,7 @@ __lroundl (long double x)
       /* Peg at max/min values, assuming that the above conversions do so.
          Strictly speaking, we can return anything for values that overflow,
          but this is more useful.  */
-      res = hi + lo;
+      res = (long int) ((unsigned long int) hi + (unsigned long int) lo);
 
       /* This is just sign(hi) == sign(lo) && sign(res) != sign(hi).  */
       if (__glibc_unlikely (((~(hi ^ lo) & (res ^ hi)) < 0)))
@@ -92,21 +93,21 @@ __lroundl (long double x)
       hi = res;
       if (xh > 0.5)
        {
-         res += 1;
+         res += 1UL;
        }
       else if (xh == 0.5)
        {
          if (xl > 0.0 || (xl == 0.0 && res >= 0))
-           res += 1;
+           res += 1UL;
        }
       else if (-xh > 0.5)
        {
-         res -= 1;
+         res -= 1UL;
        }
       else if (-xh == 0.5)
        {
          if (xl < 0.0 || (xl == 0.0 && res <= 0))
-           res -= 1;
+           res -= 1UL;
        }
 
       if (__glibc_unlikely (((~(hi ^ (res - hi)) & (res ^ hi)) < 0)))