Mail Archives: djgpp-workers/2002/03/02/11:12:06
Preferably someone that understands how the functions work should take
a look and correct them. However here's my take on it with
motivations.
Index: djgpp//src/libm/math/e_pow.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libm/math/e_pow.c,v
retrieving revision 1.1
diff -p -u -r1.1 e_pow.c
--- djgpp//src/libm/math/e_pow.c 1998/10/06 10:04:10 1.1
+++ djgpp//src/libm/math/e_pow.c 2002/03/02 14:57:07
@@ -135,7 +135,7 @@ ivln2_l = 1.92596299112661746887e-08;
k = (iy>>20)-0x3ff; /* exponent */
if(k>20) {
j = ly>>(52-k);
- if((j<<(52-k))==ly) yisint = 2-(j&1);
+ if((((__uint32_t)(j))<<(52-k))==ly) yisint = 2-(j&1);
} else if(ly==0) {
j = iy>>(20-k);
if((j<<(20-k))==iy) yisint = 2-(j&1);
__int32_t j;
__uint32_t ly;
j = ly shifted right some positions implies j < ly. The line with
the problem undoes this shift. Using j as unsigned should be safe.
Index: djgpp//src/libm/math/e_sqrt.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libm/math/e_sqrt.c,v
retrieving revision 1.1
diff -p -u -r1.1 e_sqrt.c
--- djgpp//src/libm/math/e_sqrt.c 1998/10/06 10:04:10 1.1
+++ djgpp//src/libm/math/e_sqrt.c 2002/03/02 14:57:07
@@ -160,7 +160,7 @@ static double one = 1.0, tiny=1.0e-300;
t = s0;
if((t<ix0)||((t==ix0)&&(t1<=ix1))) {
s1 = t1+r;
- if(((t1&sign)==sign)&&(s1&sign)==0) s0 += 1;
+ if((t1&sign)&&(s1&sign)==0) s0 += 1;
ix0 -= t;
if (ix1 < t1) ix0 -= 1;
ix1 -= t1;
__int32_t sign = (int)0x80000000U;
__uint32_t t1,s1;
(t1&sign)==sign checks if the sign bit is set or not. The comparision
with sign should be uneccessary.
Index: djgpp//src/libm/math/ef_j0.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libm/math/ef_j0.c,v
retrieving revision 1.1
diff -p -u -r1.1 ef_j0.c
--- djgpp//src/libm/math/ef_j0.c 1998/02/07 14:13:26 1.1
+++ djgpp//src/libm/math/ef_j0.c 2002/03/02 14:57:07
@@ -74,7 +74,7 @@ static float zero = 0.0;
* j0(x) = 1/sqrt(pi) * (P(0,x)*cc - Q(0,x)*ss) / sqrt(x)
* y0(x) = 1/sqrt(pi) * (P(0,x)*ss + Q(0,x)*cc) / sqrt(x)
*/
- if(ix>0x80000000U) z = (invsqrtpi*cc)/__ieee754_sqrtf(x);
+ if((__uint32_t)ix>0x80000000U) z = (invsqrtpi*cc)/__ieee754_sqrt
f(x);
else {
u = pzerof(x); v = qzerof(x);
z = invsqrtpi*(u*cc-v*ss)/__ieee754_sqrtf(x);
@@ -156,7 +156,7 @@ v04 = 4.4111031494e-10; /* 0x2ff280c2
if ((s*c)<zero) cc = z/ss;
else ss = z/cc;
}
- if(ix>0x80000000U) z = (invsqrtpi*ss)/__ieee754_sqrtf(x);
+ if((__uint32_t)ix>0x80000000U) z = (invsqrtpi*ss)/__ieee754_sqrtf(x);
else {
u = pzerof(x); v = qzerof(x);
z = invsqrtpi*(u*ss+v*cc)/__ieee754_sqrtf(x);
__int32_t ix;
Index: djgpp//src/libm/math/ef_j1.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libm/math/ef_j1.c,v
retrieving revision 1.1
diff -p -u -r1.1 ef_j1.c
--- djgpp//src/libm/math/ef_j1.c 1998/02/07 14:13:26 1.1
+++ djgpp//src/libm/math/ef_j1.c 2002/03/02 14:57:15
@@ -75,7 +75,7 @@ static float zero = 0.0;
* j1(x) = 1/sqrt(pi) * (P(1,x)*cc - Q(1,x)*ss) / sqrt(x)
* y1(x) = 1/sqrt(pi) * (P(1,x)*ss + Q(1,x)*cc) / sqrt(x)
*/
- if(ix>0x80000000U) z = (invsqrtpi*cc)/__ieee754_sqrtf(y);
+ if((__uint32_t)ix>0x80000000U) z = (invsqrtpi*cc)/__ieee754_sqrt
f(y);
else {
u = ponef(y); v = qonef(y);
z = invsqrtpi*(u*cc-v*ss)/__ieee754_sqrtf(y);
__int32_t ix;
The author must have wanted ix be unsigned here, otherwise he wouldn't
have coded 0x80000000U.
Index: djgpp//src/libm/math/ef_jn.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libm/math/ef_jn.c,v
retrieving revision 1.1
diff -p -u -r1.1 ef_jn.c
--- djgpp//src/libm/math/ef_jn.c 1998/02/07 14:13:24 1.1
+++ djgpp//src/libm/math/ef_jn.c 2002/03/02 14:57:15
@@ -197,7 +197,7 @@ static float zero = 0.0000000000e+00;
b = __ieee754_y1f(x);
/* quit if b is -inf */
GET_FLOAT_WORD(ib,b);
- for(i=1;i<n&&ib!=0xff800000U;i++){
+ for(i=1;i<n&&(__uint32_t)ib!=0xff800000U;i++){
temp = b;
b = ((float)(i+i)/x)*b - a;
GET_FLOAT_WORD(ib,b);
__int32_t ib;
The author must have wanted ib be unsigned here, otherwise he wouldn't
have coded 0xff800000U. Perhaps the right correction should be to make
0xff800000U 0xff800000?
Index: djgpp//src/libm/math/ef_pow.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libm/math/ef_pow.c,v
retrieving revision 1.1
diff -p -u -r1.1 ef_pow.c
--- djgpp//src/libm/math/ef_pow.c 1998/10/06 10:04:10 1.1
+++ djgpp//src/libm/math/ef_pow.c 2002/03/02 14:57:16
@@ -217,7 +217,7 @@ ivln2_l = 7.0526075433e-06; /* 0x36eca
}
else if ((j&0x7fffffff)>0x43160000) /* z <= -150 */
return s*tiny*tiny; /* underflow */
- else if (j==0xc3160000U){ /* z == -150 */
+ else if ((__uint32_t)j==0xc3160000U){ /* z == -150 */
if(p_l<=z-p_h) return s*tiny*tiny; /* underflow */
}
/*
__int32_t j;
The author must have wanted j be unsigned here, otherwise he wouldn't
have coded 0xc3160000U. Perhaps the right correction should be to make
0xc3160000U 0xc3160000?
Index: djgpp//src/libm/math/ef_rem_pio2.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libm/math/ef_rem_pio2.c,v
retrieving revision 1.1
diff -p -u -r1.1 ef_rem_pio2.c
--- djgpp//src/libm/math/ef_rem_pio2.c 1998/10/06 10:04:12 1.1
+++ djgpp//src/libm/math/ef_rem_pio2.c 2002/03/02 14:57:16
@@ -143,7 +143,7 @@ pio2_3t = 6.1232342629e-17; /* 0x248d31
fn = (float)n;
r = t-fn*pio2_1;
w = fn*pio2_1t; /* 1st round good to 40 bit */
- if(n<32&&(ix&0xffffff00U)!=npio2_hw[n-1]) {
+ if(n<32&&((__int32_t)(ix&0xffffff00U))!=npio2_hw[n-1]) {
y[0] = r-w; /* quick check no cancellation */
} else {
__uint32_t high;
__int32_t ix;
static __int32_t npio2_hw[];
We mask out the interesting bits from ix and want to compare with values
that are signed. Let's make the left value signed as well. Perhaps the
right correction should be to make 0xffffff00U 0xffffff00?
Index: djgpp//src/libm/math/s_ceil.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libm/math/s_ceil.c,v
retrieving revision 1.1
diff -p -u -r1.1 s_ceil.c
--- djgpp//src/libm/math/s_ceil.c 1998/02/07 13:47:36 1.1
+++ djgpp//src/libm/math/s_ceil.c 2002/03/02 15:23:53
@@ -66,7 +66,7 @@ static double huge = 1.0e300;
if(j_0==20) i0+=1;
else {
j = i1 + (1<<(52-j_0));
- if(j<i1) i0+=1; /* got a carry */
+ if( (0<=i1) && (j<(__uint32_t)i1) ) i0+=1; /* got a
carry */
i1 = j;
}
}
__int32_t i1;
__uint32_t j;
Index: djgpp//src/libm/math/s_floor.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libm/math/s_floor.c,v
retrieving revision 1.1
diff -p -u -r1.1 s_floor.c
--- djgpp//src/libm/math/s_floor.c 1998/02/07 13:47:34 1.1
+++ djgpp//src/libm/math/s_floor.c 2002/03/02 15:23:53
@@ -120,7 +120,7 @@ static double huge = 1.0e300;
if(j_0==20) i0+=1;
else {
j = i1+(1<<(52-j_0));
- if(j<i1) i0 +=1 ; /* got a carry */
+ if( (0<=i1) && (j<(__uint32_t)i1) ) i0 +=1 ; /* got a
carry */
i1=j;
}
}
__int32_t i1;
__uint32_t j;
i1 < 0 implies false as j is unsigned. So we only do this if i >= 0 and
then the cast is ok.
Right,
MartinS
- Raw text -