X-Authentication-Warning: delorie.com: mailnull set sender to djgpp-workers-bounces using -f From: Martin Str|mberg Message-Id: <200203021531.QAA04573@father.ludd.luth.se> Subject: libm signed/unsigned warnings To: djgpp-workers AT delorie DOT com (DJGPP-WORKERS) Date: Sat, 2 Mar 2002 16:31:16 +0100 (MET) X-Mailer: ELM [version 2.4ME+ PL54 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Reply-To: djgpp-workers AT delorie DOT com 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((t0x80000000U) 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)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;i0x43160000) /* 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= 0 and then the cast is ok. Right, MartinS