Branch: Tag:

2018-05-10

2018-05-10 21:54:44 by Tobias S. Josefowitz <tobij@tobij.de>

ADT.CritBit.BigNumTree: off by one error (removed)

Due to an off-by-one error the last limb of bignums was never compared.
This resulted (sometimes) in bignums comparing equal inside of the tree.

19:   #define cb_char CB_NAME(char)      static CB_INLINE unsigned INT32 gclz(mp_limb_t a) { -  if (sizeof(mp_limb_t) == 8) { + #if GMP_NUMB_BITS == 64    return clz64((unsigned INT64)a); -  } else { + #elif GMP_NUMB_BITS == 32    return clz32((unsigned INT32)a); -  + #else + #error Only supports limb sizes of 32 or 64 bits. + #endif   } - } +       #define O2G(o) ((MP_INT*)(o->storage))   #define K2G(k) ((MP_INT*)((k).str->storage))
46:    MP_INT * i = O2G(s);       n += abs(i->_mp_size); -  if (n > 0) { -  //fprintf(stderr, ">> %lld %lld\n", n, i->_mp_d[abs(n)]); -  return i->_mp_d[abs(i->_mp_size)-n]; +  if (n >= 0) { +  return i->_mp_d[abs(i->_mp_size) - 1 - n];    } else { -  //fprintf(stderr, "»» %lld %lld\n", n, i->_mp_d[abs(n)]); +     return 0;    }   }