From 0e069029a8bb132876d315242054a312ae106852 Mon Sep 17 00:00:00 2001 From: Joseph Myers Date: Fri, 9 Oct 2015 00:32:14 +0000 Subject: Fix dbl-64 lrint for 64-bit long (bug 19095). The dbl-64 implementation of lrint produces incorrect results for some arguments with 64-bit long because a 32-bit (unsigned) low part of the mantissa is shifted left, losing high bits in the process. This patch fixes this by casting to long int before shifting, as in lround (as this case only applies for 64-bit long, there are no issues with sign-extension). Tested for mips64 (n64). [BZ #19095] * sysdeps/ieee754/dbl-64/s_lrint.c (__lrint): Cast low part of mantissa to long int before shifting left. --- sysdeps/ieee754/dbl-64/s_lrint.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sysdeps') diff --git a/sysdeps/ieee754/dbl-64/s_lrint.c b/sysdeps/ieee754/dbl-64/s_lrint.c index 39f95adc21..d004594bc2 100644 --- a/sysdeps/ieee754/dbl-64/s_lrint.c +++ b/sysdeps/ieee754/dbl-64/s_lrint.c @@ -61,7 +61,7 @@ __lrint (double x) else if (j0 < (int32_t) (8 * sizeof (long int)) - 1) { if (j0 >= 52) - result = ((long int) i0 << (j0 - 20)) | (i1 << (j0 - 52)); + result = ((long int) i0 << (j0 - 20)) | ((long int) i1 << (j0 - 52)); else { #if defined FE_INVALID || defined FE_INEXACT -- cgit v1.2.1