diff --git a/math/libm-test.inc b/math/libm-test.inc
index ac1fe85..d3964ed 100644
--- a/math/libm-test.inc
+++ b/math/libm-test.inc
@@ -8099,25 +8099,168 @@ static const struct test_f_l_data lround_test_data[] =
     TEST_f_l (lround, 22514.5, 22515, ERRNO_UNCHANGED),
     TEST_f_l (lround, -22514.5, -22515, ERRNO_UNCHANGED),
     TEST_f_l (lround, 1071930.0008, 1071930, ERRNO_UNCHANGED),
+    TEST_f_l (lround, 2097152.5, 2097153, ERRNO_UNCHANGED),
+    TEST_f_l (lround, -2097152.5, -2097153, ERRNO_UNCHANGED),
 #ifndef TEST_FLOAT
     TEST_f_l (lround, 1073741824.01, 1073741824, ERRNO_UNCHANGED),
-# if LONG_MAX > 281474976710656
+# if LONG_MAX > 0x7fffffff
+    TEST_f_l (lround, 34359738368.5, 34359738369ll, ERRNO_UNCHANGED),
+    TEST_f_l (lround, -34359738368.5, -34359738369ll, ERRNO_UNCHANGED),
+    TEST_f_l (lround, -3.65309740835E17, -365309740835000000LL, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
     TEST_f_l (lround, 281474976710656.025, 281474976710656, ERRNO_UNCHANGED),
     TEST_f_l (lround, 18014398509481974, 18014398509481974, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
 # endif
-    TEST_f_l (lround, 2097152.5, 2097153, ERRNO_UNCHANGED),
-    TEST_f_l (lround, -2097152.5, -2097153, ERRNO_UNCHANGED),
+#endif
+
+    /* Test boundary conditions.  */
+    /* 0x1FFFFF */
+    TEST_f_l (lround, 2097151.0, 2097151LL, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    /* 0x800000 */
+    TEST_f_l (lround, 8388608.0, 8388608LL, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    /* 0x1000000 */
+    TEST_f_l (lround, 16777216.0, 16777216LL, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+#if LONG_MAX > 0x7fffffff
+    /* 0x20000000000 */
+    TEST_f_l (lround, 2199023255552.0, 2199023255552LL, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    /* 0x40000000000 */
+    TEST_f_l (lround, 4398046511104.0, 4398046511104LL, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    /* 0x1000000000000 */
+    TEST_f_l (lround, 281474976710656.0, 281474976710656LL, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    /* 0x10000000000000 */
+    TEST_f_l (lround, 4503599627370496.0, 4503599627370496LL, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    /* 0x10000080000000 */
+    TEST_f_l (lround, 4503601774854144.0, 4503601774854144LL, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    /* 0x20000000000000 */
+    TEST_f_l (lround, 9007199254740992.0, 9007199254740992LL, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    /* 0x80000000000000 */
+    TEST_f_l (lround, 36028797018963968.0, 36028797018963968LL, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    /* 0x100000000000000 */
+    TEST_f_l (lround, 72057594037927936.0, 72057594037927936LL, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+#endif
+
+#ifndef TEST_FLOAT
+# if LONG_MAX > 0x7fffffff
+    /* 0x100000000 */
+    TEST_f_l (lround, 4294967295.5, 4294967296LL, ERRNO_UNCHANGED),
+    /* 0x200000000 */
+    TEST_f_l (lround, 8589934591.5, 8589934592LL, ERRNO_UNCHANGED),
+# endif
+
     /* nextafter(0.5,-1)  */
     TEST_f_l (lround, 0x1.fffffffffffffp-2, 0, ERRNO_UNCHANGED),
     /* nextafter(-0.5,1)  */
     TEST_f_l (lround, -0x1.fffffffffffffp-2, 0, ERRNO_UNCHANGED),
-#else
-    /* nextafter(0.5,-1)  */
+# if LONG_MAX > 0x7fffffff
+    /* On PowerPC an exponent of '52' is the largest incrementally
+     * representable sequence of whole-numbers in the 'double' range.  We test
+     * lround to make sure that a guard bit set during the lround operation
+     * hasn't forced an erroneous shift giving us an incorrect result.  The odd
+     * numbers between +-(2^52+1 and 2^53-1) are affected since they have the
+     * rightmost bit set.  */
+    /* +-(2^52+1)  */
+    TEST_f_l (lround, 0x1.0000000000001p+52,4503599627370497LL, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_f_l (lround, -0x1.0000000000001p+52,-4503599627370497LL, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    /* +-(2^53-1): Input is the last (positive and negative) incrementally
+     * representable whole-number in the 'double' range that might round
+     * erroneously.  */
+    TEST_f_l (lround, 0x1.fffffffffffffp+52, 9007199254740991LL, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_f_l (lround, -0x1.fffffffffffffp+52, -9007199254740991LL, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+# endif
+#endif
     TEST_f_l (lround, 0x1.fffffp-2, 0, ERRNO_UNCHANGED),
-    /* nextafter(-0.5,1)  */
+    /* nextafter(0.5,-1)  */
+    TEST_f_l (lround, 0x1.fffffep-2, 0, ERRNO_UNCHANGED),
     TEST_f_l (lround, -0x1.fffffp-2, 0, ERRNO_UNCHANGED),
+    /* nextafter(-0.5,1)  */
+    TEST_f_l (lround, -0x1.fffffep-2, 0, ERRNO_UNCHANGED),
     TEST_f_l (lround, 0x1.fffffep+23, 16777215, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
     TEST_f_l (lround, -0x1.fffffep+23, -16777215, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    /* As above, on PowerPC an exponent of '23' is the largest incrementally
+     * representable sequence of whole-numbers in the 'float' range.
+     * Likewise, numbers between +-(2^23+1 and 2^24-1) are affected.  */
+    TEST_f_l (lround, 0x1.000002p+23,8388609, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_f_l (lround, -0x1.000002p+23,-8388609, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_f_l (lround, 0x1.fffffep+23, 16777215, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_f_l (lround, -0x1.fffffep+23, -16777215, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+
+#if LONG_MAX > 0x7fffffff
+# ifdef TEST_LDOUBLE
+    /* The input can only be represented in long double.  */
+    TEST_f_l (lround, 4503599627370495.5L, 4503599627370496LL, ERRNO_UNCHANGED),
+    TEST_f_l (lround, 4503599627370496.25L, 4503599627370496LL, ERRNO_UNCHANGED),
+    TEST_f_l (lround, 4503599627370496.5L, 4503599627370497LL, ERRNO_UNCHANGED),
+    TEST_f_l (lround, 4503599627370496.75L, 4503599627370497LL, ERRNO_UNCHANGED),
+    TEST_f_l (lround, 4503599627370497.5L, 4503599627370498LL, ERRNO_UNCHANGED),
+
+#  if LDBL_MANT_DIG > 100
+    TEST_f_l (lround, 4503599627370495.4999999999999L, 4503599627370495LL, ERRNO_UNCHANGED),
+    TEST_f_l (lround, 4503599627370496.4999999999999L, 4503599627370496LL, ERRNO_UNCHANGED),
+    TEST_f_l (lround, 4503599627370497.4999999999999L, 4503599627370497LL, ERRNO_UNCHANGED),
+    TEST_f_l (lround, 4503599627370494.5000000000001L, 4503599627370495LL, ERRNO_UNCHANGED),
+    TEST_f_l (lround, 4503599627370495.5000000000001L, 4503599627370496LL, ERRNO_UNCHANGED),
+    TEST_f_l (lround, 4503599627370496.5000000000001L, 4503599627370497LL, ERRNO_UNCHANGED),
+
+    TEST_f_l (lround, -4503599627370495.4999999999999L, -4503599627370495LL, ERRNO_UNCHANGED),
+    TEST_f_l (lround, -4503599627370496.4999999999999L, -4503599627370496LL, ERRNO_UNCHANGED),
+    TEST_f_l (lround, -4503599627370497.4999999999999L, -4503599627370497LL, ERRNO_UNCHANGED),
+    TEST_f_l (lround, -4503599627370494.5000000000001L, -4503599627370495LL, ERRNO_UNCHANGED),
+    TEST_f_l (lround, -4503599627370495.5000000000001L, -4503599627370496LL, ERRNO_UNCHANGED),
+    TEST_f_l (lround, -4503599627370496.5000000000001L, -4503599627370497LL, ERRNO_UNCHANGED),
+#  endif
+
+    TEST_f_l (lround, -4503599627370495.5L, -4503599627370496LL, ERRNO_UNCHANGED),
+    TEST_f_l (lround, -4503599627370496.25L, -4503599627370496LL, ERRNO_UNCHANGED),
+    TEST_f_l (lround, -4503599627370496.5L, -4503599627370497LL, ERRNO_UNCHANGED),
+    TEST_f_l (lround, -4503599627370496.75L, -4503599627370497LL, ERRNO_UNCHANGED),
+    TEST_f_l (lround, -4503599627370497.5L, -4503599627370498LL, ERRNO_UNCHANGED),
+
+    TEST_f_l (lround, 9007199254740991.5L, 9007199254740992LL, ERRNO_UNCHANGED),
+    TEST_f_l (lround, 9007199254740992.25L, 9007199254740992LL, ERRNO_UNCHANGED),
+    TEST_f_l (lround, 9007199254740992.5L, 9007199254740993LL, ERRNO_UNCHANGED),
+    TEST_f_l (lround, 9007199254740992.75L, 9007199254740993LL, ERRNO_UNCHANGED),
+    TEST_f_l (lround, 9007199254740993.5L, 9007199254740994LL, ERRNO_UNCHANGED),
+
+#  if LDBL_MANT_DIG > 100
+    TEST_f_l (lround, 9007199254740991.4999999999999L, 9007199254740991LL, ERRNO_UNCHANGED),
+    TEST_f_l (lround, 9007199254740992.4999999999999L, 9007199254740992LL, ERRNO_UNCHANGED),
+    TEST_f_l (lround, 9007199254740993.4999999999999L, 9007199254740993LL, ERRNO_UNCHANGED),
+    TEST_f_l (lround, 9007199254740991.5000000000001L, 9007199254740992LL, ERRNO_UNCHANGED),
+    TEST_f_l (lround, 9007199254740992.5000000000001L, 9007199254740993LL, ERRNO_UNCHANGED),
+    TEST_f_l (lround, 9007199254740993.5000000000001L, 9007199254740994LL, ERRNO_UNCHANGED),
+
+    TEST_f_l (lround, -9007199254740991.4999999999999L, -9007199254740991LL, ERRNO_UNCHANGED),
+    TEST_f_l (lround, -9007199254740992.4999999999999L, -9007199254740992LL, ERRNO_UNCHANGED),
+    TEST_f_l (lround, -9007199254740993.4999999999999L, -9007199254740993LL, ERRNO_UNCHANGED),
+    TEST_f_l (lround, -9007199254740991.5000000000001L, -9007199254740992LL, ERRNO_UNCHANGED),
+    TEST_f_l (lround, -9007199254740992.5000000000001L, -9007199254740993LL, ERRNO_UNCHANGED),
+    TEST_f_l (lround, -9007199254740993.5000000000001L, -9007199254740994LL, ERRNO_UNCHANGED),
+#  endif
+
+    TEST_f_l (lround, -9007199254740991.5L, -9007199254740992LL, ERRNO_UNCHANGED),
+    TEST_f_l (lround, -9007199254740992.25L, -9007199254740992LL, ERRNO_UNCHANGED),
+    TEST_f_l (lround, -9007199254740992.5L, -9007199254740993LL, ERRNO_UNCHANGED),
+    TEST_f_l (lround, -9007199254740992.75L, -9007199254740993LL, ERRNO_UNCHANGED),
+    TEST_f_l (lround, -9007199254740993.5L, -9007199254740994LL, ERRNO_UNCHANGED),
+
+    TEST_f_l (lround, 72057594037927935.5L, 72057594037927936LL, ERRNO_UNCHANGED),
+    TEST_f_l (lround, 72057594037927936.25L, 72057594037927936LL, ERRNO_UNCHANGED),
+    TEST_f_l (lround, 72057594037927936.5L, 72057594037927937LL, ERRNO_UNCHANGED),
+    TEST_f_l (lround, 72057594037927936.75L, 72057594037927937LL, ERRNO_UNCHANGED),
+    TEST_f_l (lround, 72057594037927937.5L, 72057594037927938LL, ERRNO_UNCHANGED),
+
+    TEST_f_l (lround, -72057594037927935.5L, -72057594037927936LL, ERRNO_UNCHANGED),
+    TEST_f_l (lround, -72057594037927936.25L, -72057594037927936LL, ERRNO_UNCHANGED),
+    TEST_f_l (lround, -72057594037927936.5L, -72057594037927937LL, ERRNO_UNCHANGED),
+    TEST_f_l (lround, -72057594037927936.75L, -72057594037927937LL, ERRNO_UNCHANGED),
+    TEST_f_l (lround, -72057594037927937.5L, -72057594037927938LL, ERRNO_UNCHANGED),
+
+    TEST_f_l (lround, 9223372036854775806.25L, 9223372036854775806LL, ERRNO_UNCHANGED),
+    TEST_f_l (lround, -9223372036854775806.25L, -9223372036854775806LL, ERRNO_UNCHANGED),
+    TEST_f_l (lround, 9223372036854775806.5L, 9223372036854775807LL, ERRNO_UNCHANGED),
+    TEST_f_l (lround, -9223372036854775806.5L, -9223372036854775807LL, ERRNO_UNCHANGED),
+    TEST_f_l (lround, 9223372036854775807.0L, 9223372036854775807LL, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_f_l (lround, -9223372036854775807.0L, -9223372036854775807LL, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+# endif
 #endif
   };
 
@@ -8147,12 +8290,15 @@ static const struct test_f_L_data llround_test_data[] =
     TEST_f_L (llround, 22514.5, 22515, ERRNO_UNCHANGED),
     TEST_f_L (llround, -22514.5, -22515, ERRNO_UNCHANGED),
     TEST_f_L (llround, 1071930.0008, 1071930, ERRNO_UNCHANGED),
-#ifndef TEST_FLOAT
     TEST_f_L (llround, 2097152.5, 2097153, ERRNO_UNCHANGED),
     TEST_f_L (llround, -2097152.5, -2097153, ERRNO_UNCHANGED),
+#ifndef TEST_FLOAT
+    TEST_f_L (llround, 1073741824.01, 1073741824, ERRNO_UNCHANGED),
     TEST_f_L (llround, 34359738368.5, 34359738369ll, ERRNO_UNCHANGED),
     TEST_f_L (llround, -34359738368.5, -34359738369ll, ERRNO_UNCHANGED),
-    TEST_f_L (llround, -3.65309740835E17, -365309740835000000LL, ERRNO_UNCHANGED),
+    TEST_f_L (llround, -3.65309740835E17, -365309740835000000LL, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_f_L (llround, 281474976710656.025, 281474976710656, ERRNO_UNCHANGED),
+    TEST_f_L (llround, 18014398509481974, 18014398509481974, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
 #endif
 
     /* Test boundary conditions.  */
@@ -8203,11 +8349,15 @@ static const struct test_f_L_data llround_test_data[] =
      * erroneously.  */
     TEST_f_L (llround, 0x1.fffffffffffffp+52, 9007199254740991LL, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
     TEST_f_L (llround, -0x1.fffffffffffffp+52, -9007199254740991LL, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
-#else
+#endif
+    TEST_f_L (llround, 0x1.fffffp-2, 0, ERRNO_UNCHANGED),
     /* nextafter(0.5,-1)  */
     TEST_f_L (llround, 0x1.fffffep-2, 0, ERRNO_UNCHANGED),
+    TEST_f_L (llround, -0x1.fffffp-2, 0, ERRNO_UNCHANGED),
     /* nextafter(-0.5,1)  */
     TEST_f_L (llround, -0x1.fffffep-2, 0, ERRNO_UNCHANGED),
+    TEST_f_L (llround, 0x1.fffffep+23, 16777215, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_f_L (llround, -0x1.fffffep+23, -16777215, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
     /* As above, on PowerPC an exponent of '23' is the largest incrementally
      * representable sequence of whole-numbers in the 'float' range.
      * Likewise, numbers between +-(2^23+1 and 2^24-1) are affected.  */
@@ -8215,8 +8365,6 @@ static const struct test_f_L_data llround_test_data[] =
     TEST_f_L (llround, -0x1.000002p+23,-8388609, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
     TEST_f_L (llround, 0x1.fffffep+23, 16777215, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
     TEST_f_L (llround, -0x1.fffffep+23, -16777215, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
-#endif
-
 
 #ifdef TEST_LDOUBLE
     /* The input can only be represented in long double.  */
diff --git a/sysdeps/ieee754/ldbl-96/s_lroundl.c b/sysdeps/ieee754/ldbl-96/s_lroundl.c
index e34edd3..7a59835 100644
--- a/sysdeps/ieee754/ldbl-96/s_lroundl.c
+++ b/sysdeps/ieee754/ldbl-96/s_lroundl.c
@@ -58,13 +58,15 @@ __lroundl (long double x)
       else
 	{
 	  u_int32_t j = i1 + (0x80000000 >> (j0 - 31));
+	  unsigned long int ures = i0;
+
 	  if (j < i1)
-	    ++i0;
+	    ++ures;
 
 	  if (j0 == 31)
-	    result = (long int) i0;
+	    result = ures;
 	  else
-	    result = ((long int) i0 << (j0 - 31)) | (j >> (63 - j0));
+	    result = (ures << (j0 - 31)) | (j >> (63 - j0));
 	}
     }
   else
