Skip to content

Commit 53c2103

Browse files
committed
math/ld/ld128: Use 'lsl' for left shifts in fmodl, hypotl and remquol
These all iterate until a value flips sign by shifting a bit left, and that only works if you do the shift using unsigned arithmetic and then cast back to signed. Signed-off-by: Keith Packard <[email protected]>
1 parent be7826f commit 53c2103

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

newlib/libm/ld/ld128/e_fmodl.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,18 @@ fmodl(long double x, long double y)
5050
/* determine ix = ilogb(x) */
5151
if(hx<0x0001000000000000LL) { /* subnormal x */
5252
if(hx==0) {
53-
for (ix = -16431, i=lx; i>0; i<<=1) ix -=1;
53+
for (ix = -16431, i=lx; i>0; i=lsl(i, 1)) ix -=1;
5454
} else {
55-
for (ix = -16382, i=hx<<15; i>0; i<<=1) ix -=1;
55+
for (ix = -16382, i=lsl(hx, 15); i>0; i=lsl(i, 1)) ix -=1;
5656
}
5757
} else ix = (hx>>48)-0x3fff;
5858

5959
/* determine iy = ilogb(y) */
6060
if(hy<0x0001000000000000LL) { /* subnormal y */
6161
if(hy==0) {
62-
for (iy = -16431, i=ly; i>0; i<<=1) iy -=1;
62+
for (iy = -16431, i=ly; i>0; i=lsl(i, 1)) iy -=1;
6363
} else {
64-
for (iy = -16382, i=hy<<15; i>0; i<<=1) iy -=1;
64+
for (iy = -16382, i=lsl(hy, 15); i>0; i=lsl(i, 1)) iy -=1;
6565
}
6666
} else iy = (hy>>48)-0x3fff;
6767

newlib/libm/ld/ld128/e_hypotl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ hypotl(long double x, long double y)
116116
u_int64_t high;
117117
t1 = 1.0L;
118118
GET_LDOUBLE_MSW64(high,t1);
119-
SET_LDOUBLE_MSW64(t1,high+(k<<48));
119+
SET_LDOUBLE_MSW64(t1,high+lsl(k, 48));
120120
return check_oflowl(t1*w);
121121
} else return w;
122122
}

newlib/libm/ld/ld128/s_remquol.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ remquol(long double x, long double y, int *quo)
115115
hz=_hx-hy;lz=lx-ly; if(lx<ly) hz -= 1;
116116
if(hz<0){_hx = _hx+_hx+(lx>>MANL_SHIFT); lx = lx+lx;}
117117
else {_hx = hz+hz+(lz>>MANL_SHIFT); lx = lz+lz; q++;}
118-
q <<= 1;
118+
q = lsl(q, 1);
119119
}
120120
hz=_hx-hy;lz=lx-ly; if(lx<ly) hz -= 1;
121121
if(hz>=0) {_hx=hz;lx=lz;q++;}

0 commit comments

Comments
 (0)