This is the mail archive of the libc-hacker@sources.redhat.com mailing list for the glibc project.
Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Hi!
ldbl-96 llroundl(4294967295.5) returns 0, although it should return
4294967296LL.
The problem is that on this input i0 == 0xffffffff, i1 == 0x80000000, j0 == 31,
so llroundl rounds up (by doing ++i0, which overflows and is suddenly 0).
Fixed with a patch below, where the rounding is already done on long long
variable.
2001-06-04 Jakub Jelinek <jakub@redhat.com>
* math/libm-test.inc (llround_test): Add two new llround tests.
* sysdeps/ieee754/ldbl-96/s_llroundl.c (__llroundl): Don't allow
overflow when rounding away from zero.
--- libc/math/libm-test.inc.jj Wed May 23 09:21:45 2001
+++ libc/math/libm-test.inc Mon Jun 4 10:01:59 2001
@@ -3302,6 +3302,13 @@ llround_test (void)
/* 0x100000000000000 */
TEST_f_L (llround, 72057594037927936.0, 72057594037927936LL);
+#ifndef TEST_FLOAT
+ /* 0x100000000 */
+ TEST_f_L (llround, 4294967295.5, 4294967296LL);
+ /* 0x200000000 */
+ TEST_f_L (llround, 8589934591.5, 8589934592LL);
+#endif
+
END (llround);
}
--- libc/sysdeps/ieee754/ldbl-96/s_llroundl.c.jj Wed Jul 14 02:14:08 1999
+++ libc/sysdeps/ieee754/ldbl-96/s_llroundl.c Mon Jun 4 09:50:49 2001
@@ -1,5 +1,5 @@
/* Round long double value to long long int.
- Copyright (C) 1997 Free Software Foundation, Inc.
+ Copyright (C) 1997, 2001 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
@@ -59,13 +59,13 @@ __llroundl (long double x)
else
{
u_int32_t j = i1 + (0x80000000 >> (j0 - 31));
+
+ result = (long long int) i0;
if (j < i1)
- ++i0;
+ ++result;
- if (j0 == 31)
- result = (long long int) i0;
- else
- result = ((long long int) i0 << (j0 - 31)) | (j >> (63 - j0));
+ if (j0 > 31)
+ result = (result << (j0 - 31)) | (j >> (63 - j0));
}
}
else
Jakub
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |