> Date: Wed, 19 Aug 2015 21:25:35 +0200
> From: Christian Weisgerber <[email protected]>
>
> I saw this drifting by on FreeBSD (from Dimitry Andric):
>
> In libm's exp2(3), avoid left-shifting a negative integer, which is
> undefined. Replace it with the intended value, in a defined way.
>
> OK? Don't bother?
ok kettenis@
> Index: src/s_exp2.c
> ===================================================================
> RCS file: /cvs/src/lib/libm/src/s_exp2.c,v
> retrieving revision 1.7
> diff -u -p -r1.7 s_exp2.c
> --- src/s_exp2.c 3 Jul 2013 04:46:36 -0000 1.7
> +++ src/s_exp2.c 19 Aug 2015 19:10:38 -0000
> @@ -373,14 +373,14 @@ exp2(double x)
> /* Compute r = exp2(y) = exp2t[i0] * p(z - eps[i]). */
> t = tbl[i0]; /* exp2t[i0] */
> z -= tbl[i0 + 1]; /* eps[i0] */
> - if (k >= -1021 << 20)
> + if (k >= -(1021 << 20))
> INSERT_WORDS(twopk, 0x3ff00000 + k, 0);
> else
> INSERT_WORDS(twopkp1000, 0x3ff00000 + k + (1000 << 20), 0);
> r = t + t * z * (P1 + z * (P2 + z * (P3 + z * (P4 + z * P5))));
>
> /* Scale by 2**(k>>20). */
> - if(k >= -1021 << 20) {
> + if(k >= -(1021 << 20)) {
> if (k == 1024 << 20)
> return (r * 2.0 * 0x1p1023);
> return (r * twopk);
> --
> Christian "naddy" Weisgerber [email protected]
>
>