Browse Source

Avoid shifting a 32-bit zero value by more than 31 bits.

master
Bruno Haible 20 years ago
parent
commit
1e7aede9bd
  1. 5
      ChangeLog
  2. 12
      src/integer/bitwise/cl_I_ash_I.cc

5
ChangeLog

@ -1,3 +1,8 @@
2005-08-27 Bruno Haible <bruno@clisp.org>
* src/integer/bitwise/cl_I_ash_I.cc (ash): Avoid shifting a 32-bit
zero value by more than 31 bits.
2005-08-27 Bruno Haible <bruno@clisp.org>
Make the long-float overflow check work on 64-bit platforms.

12
src/integer/bitwise/cl_I_ash_I.cc

@ -52,6 +52,7 @@ const cl_I ash (const cl_I& x, const cl_I& y)
|| len == ceiling(log2_intDsize+intCsize+1,intDsize))
if (mspref(arrayMSDptr(bn->data,len),0) >= (uintD)bit((log2_intDsize+intCsize)%intDsize))
cl_ash_error(y);
#if (log2_intDsize+intCsize > intDsize)
#define IF_LENGTH(i) \
if (bn_minlength <= i && i <= ceiling(log2_intDsize+intCsize+1,intDsize) && (i == ceiling(log2_intDsize+intCsize+1,intDsize) || len == i))
IF_LENGTH(1)
@ -68,6 +69,11 @@ const cl_I ash (const cl_I& x, const cl_I& y)
cl_abort();
#undef IF_LENGTH
k = k << (intDsize-log2_intDsize);
#else
// log2_intDsize+intCsize <= intDsize,
// implies len==1 or len==2 && lspref(arrayLSDptr(bn->data,len),1) == 0.
k = 0;
#endif
k |= lspref(arrayLSDptr(bn->data,len),0) >> log2_intDsize;
i = lspref(arrayLSDptr(bn->data,len),0) % intDsize;
#endif
@ -123,6 +129,7 @@ const cl_I ash (const cl_I& x, const cl_I& y)
|| len == ceiling(log2_intDsize+intCsize+1,intDsize))
if (mspref(arrayMSDptr(bn->data,len),0) < (uintD)(-bit((log2_intDsize+intCsize)%intDsize)))
goto sign;
#if (log2_intDsize+intCsize > intDsize)
#define IF_LENGTH(i) \
if (bn_minlength <= i && i <= ceiling(log2_intDsize+intCsize+1,intDsize) && (i == ceiling(log2_intDsize+intCsize+1,intDsize) || len == i))
IF_LENGTH(1)
@ -139,6 +146,11 @@ const cl_I ash (const cl_I& x, const cl_I& y)
cl_abort();
#undef IF_LENGTH
k = k << (intDsize-log2_intDsize);
#else
// log2_intDsize+intCsize <= intDsize,
// implies len==1 or len==2 && lspref(arrayLSDptr(bn->data,len),1) == ~0.
k = 0;
#endif
k |= (uintD)(~lspref(arrayLSDptr(bn->data,len),0)) >> log2_intDsize;
i = (uintD)(-lspref(arrayLSDptr(bn->data,len),0)) % intDsize;
if (i == 0)

Loading…
Cancel
Save