diff options
author | Martynas Venckus <martynas@cvs.openbsd.org> | 2011-04-10 20:42:10 +0000 |
---|---|---|
committer | Martynas Venckus <martynas@cvs.openbsd.org> | 2011-04-10 20:42:10 +0000 |
commit | 88e477cf6c1e288b8cb088982ed61e5ea546e8ee (patch) | |
tree | e468ad701db37b7e11ed345eb94c191e491ed253 /lib/libm | |
parent | 38f0c80c668f47b0cfed2daebebb1386bba4e452 (diff) |
The {,l}lrint{,f} functions avoid to shift results by more than 31
bits, because "behavior is implementation defined in this case".
However, this is wrong; behavior is undefined if the right operand
is greater than or equal to the width of the promoted left operand.
This broke {,l}lrint{,f} (64-bit architectures), and llrint{,f}
(32-bit architectures) where results are actually 64-bit values.
The high part was clipped for all exponents greater or equal to 52.
Fix this to use RESTYPE_BITS instead; {,l}lrint{,f} are now able
to pass our regression tests, and I think are right now.
Diffstat (limited to 'lib/libm')
-rw-r--r-- | lib/libm/src/s_lrint.c | 10 | ||||
-rw-r--r-- | lib/libm/src/s_lrintf.c | 6 |
2 files changed, 8 insertions, 8 deletions
diff --git a/lib/libm/src/s_lrint.c b/lib/libm/src/s_lrint.c index fdfdd2b7d87..fd9bc1e7a0a 100644 --- a/lib/libm/src/s_lrint.c +++ b/lib/libm/src/s_lrint.c @@ -1,4 +1,4 @@ -/* $OpenBSD: s_lrint.c,v 1.3 2011/04/10 11:35:01 martynas Exp $ */ +/* $OpenBSD: s_lrint.c,v 1.4 2011/04/10 20:42:09 martynas Exp $ */ /* $NetBSD: lrint.c,v 1.3 2004/10/13 15:18:32 drochner Exp $ */ /*- @@ -82,14 +82,14 @@ LRINTNAME(double x) shift = e - DBL_FRACBITS; if (shift >=0) - res = (shift < 32 ? (RESTYPE)i1 << shift : 0); + res = (shift < RESTYPE_BITS ? (RESTYPE)i1 << shift : 0); else - res = (shift > -32 ? i1 >> -shift : 0); + res = (shift > -RESTYPE_BITS ? i1 >> -shift : 0); shift += 32; if (shift >=0) - res |= (shift < 32 ? (RESTYPE)i0 << shift : 0); + res |= (shift < RESTYPE_BITS ? (RESTYPE)i0 << shift : 0); else - res |= (shift > -32 ? i0 >> -shift : 0); + res |= (shift > -RESTYPE_BITS ? i0 >> -shift : 0); return (s ? -res : res); } diff --git a/lib/libm/src/s_lrintf.c b/lib/libm/src/s_lrintf.c index d86f2bb9eb4..5844909a4c6 100644 --- a/lib/libm/src/s_lrintf.c +++ b/lib/libm/src/s_lrintf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: s_lrintf.c,v 1.2 2011/04/10 11:25:14 martynas Exp $ */ +/* $OpenBSD: s_lrintf.c,v 1.3 2011/04/10 20:42:09 martynas Exp $ */ /* $NetBSD: lrintf.c,v 1.3 2004/10/13 15:18:32 drochner Exp $ */ /*- @@ -84,9 +84,9 @@ LRINTNAME(float x) shift = e - SNG_FRACBITS; if (shift >=0) - res = (shift < 32 ? (RESTYPE)i0 << shift : 0); + res = (shift < RESTYPE_BITS ? (RESTYPE)i0 << shift : 0); else - res = (shift > -32 ? i0 >> -shift : 0); + res = (shift > -RESTYPE_BITS ? i0 >> -shift : 0); return (s ? -res : res); } |