Following test case returns 2, which should be 0.
int main() {
  long x = lrint(0.5);
  printf("%ld", x);
  return 0;
}

Fix from glibc commit 6624dbc07b5a9fb316ed188ef01f65b8eea8b47c

Signed-off-by: Waldemar Brodkorb <[email protected]>
---
 libm/s_lrint.c | 20 +++++++-------------
 1 file changed, 7 insertions(+), 13 deletions(-)

diff --git a/libm/s_lrint.c b/libm/s_lrint.c
index 09800d8de..2a8db9fbe 100644
--- a/libm/s_lrint.c
+++ b/libm/s_lrint.c
@@ -49,19 +49,13 @@ lrint (double x)
 
   if (_j0 < 20)
     {
-      if (_j0 < -1)
-       return 0;
-      else
-       {
-         w = two52[sx] + x;
-         t = w - two52[sx];
-         EXTRACT_WORDS (i0, i1, t);
-         _j0 = ((i0 >> 20) & 0x7ff) - 0x3ff;
-         i0 &= 0xfffff;
-         i0 |= 0x100000;
-
-         result = i0 >> (20 - _j0);
-       }
+      w = two52[sx] + x;
+      t = w - two52[sx];
+      EXTRACT_WORDS (i0, i1, t);
+      _j0 = ((i0 >> 20) & 0x7ff) - 0x3ff;
+      i0 &= 0xfffff;
+      i0 |= 0x100000;
+      result = (_j0 < 0 ? 0 : i0 >> (20 - _j0));
     }
   else if (_j0 < (int32_t) (8 * sizeof (long int)) - 1)
     {
-- 
2.30.2

_______________________________________________
devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to