ChordID.getDistance() returns negative value

Home Forums PeerfactSim Forum ChordID.getDistance() returns negative value

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • #915

    I stumple accross some unusual behavior. I pretty sure it is a bug,
    but I need confirmation 🙂

    The distance method of the chord node class is defined as followed:

    public int getDistance(ChordID id) {
    BigInteger oid = id.getValue();

    I assumed that abs() is returning the absolute value of the BigInteger
    oid as explained in the corresponding javadoc. Therefore I thought
    that the distance is always positive. But my debugging showed that
    this is not the case.
    Is this a bug?

    P.S.: I helped myself by using Math.abs() on the return value.

    Matthias Feldotto

    I think there is a bigger problem. The method abs() of BigInteger
    should work correctly. The problem occurs by using the method

    BigInteger can contain values which do not fit into a normal integer.
    Because of the overflow you get negative values.

    To work with it correctly, change the return type of the method to
    BigInteger and remove the call of intValue() at the end. You only have
    to make two self-explanatory changes in other classes
    to make the code compile clean.

    The bug will be fixed in the next simulator version for all users.


    you are right. the problem lies in the intValue() function. Although
    it is quite difficult to express the difference of two 160bit numbers
    in a 32bit number… most of the time this won’t work.

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.

Comments are closed.