Menu

#105 OnBC: Faulty division of negative long integers

Bug
open
nobody
OnBoard C (71)
5
2004-01-29
2003-11-26
Ari Ojamies
No

OnBoardC 2.3

Division of one long integer by another one seems to
work only if both of them have the same sign.

{
Int32 a, b, c;

...

c = a / b;
}

For a=-6, b=3 ---> c = -6 results.
For a=6, b=-3 ---> c = -6 results.

For a=-6, b=-3 ---> c = 2 results. OK
For a=6, b=3 ---> c = 2 results. OK

Discussion

  • Nick Guenther

    Nick Guenther - 2003-11-29

    Logged In: YES
    user_id=705725

    Hmm... I think I found a similar trouble, but I just noted
    it down in a memo quickly so this might not be right:

    Int x, z;
    PointType p; //both members are of type int
    //...
    (x-p.x)/z ---> if x-p.x works out to be negative, the result
    is the value of x-p.x, ignoring "/z"
    If x is a double the trouble goes away (I'm guessing that
    would cast p.x to a double, which results in casting z to
    double and appearantly there is no bug there).

     
  • John Wilund

    John Wilund - 2003-12-01

    Logged In: YES
    user_id=574706

    I can not recreate this BUG. (OnBC/Asm v.2.3)

    static Boolean test(void){
    Int32 a, b, c;
    a = -6;
    b = 3;
    c = a/b;
    if (c = -2)
    return 0; // upon success!
    else
    return 1; // upon failure.
    }

    This function will return 0 for me.
    Anyone else having other results?

    /John

     
  • Ari Ojamies

    Ari Ojamies - 2003-12-01

    Logged In: YES
    user_id=918424

    John,

    please change the line
    if (c = -2)
    of your test function by
    if (c == -2)

    . Otherwise the function will always show the same result
    regardless of the values used. On my m515 that code returns 1.
    I repeated the test using first Int16 and then Int8. But the
    error occured when using Int32 only.

    Ari

     
  • John Wilund

    John Wilund - 2003-12-01

    Logged In: YES
    user_id=574706

    Hi all,

    I was wrong!

    There IS a BUG in v.2.3!

    Thanks for correcting mw!

    /John

     
  • John Wilund

    John Wilund - 2003-12-01

    Logged In: YES
    user_id=574706

    Hi all,

    I was wrong!

    There IS a BUG in v.2.3!

    Thanks for correcting mw!

    /John

     
  • John Wilund

    John Wilund - 2003-12-01

    Logged In: YES
    user_id=574706

    Hi all,

    I was wrong!

    There IS a BUG in v.2.3!

    Thanks for correcting mw!

    /John

     
  • John Wilund

    John Wilund - 2003-12-03

    Logged In: YES
    user_id=574706

    Yes to fixing this.

    static Boolean test(void){
    Int32 a, b, c;
    a = -6;
    b = 3;
    c = a/b;
    if (c == -2) // Thanks Ari.
    return 0; // upon success!
    else
    return 1; // upon failure.
    }

    It strange: this litte function assembles to aprox. 300 bytes
    of code!

     
  • Wade Guthrie

    Wade Guthrie - 2004-01-29
    • labels: --> OnBoard C
    • milestone: --> Bug
    • summary: Faulty division of negative long integers --> OnBC: Faulty division of negative long integers
     

Log in to post a comment.