Shop OBEX P1 Docs P2 Docs Learn Events
UnsignedIntMath.java problem in umulf fonction — Parallax Forums

UnsignedIntMath.java problem in umulf fonction

cybermimilcybermimil Posts: 10
edited 2007-12-13 08:45 in General Discussion
What is this command in method umulf (row 125):

public static int umulf(int value, int fraction) {
int i, result=0, rest=0;
for (i=1; i<17; i++) {
if (fraction < 0) { //b15 set
result += (value >>> i); //accumulate integer result
rest += ( (value & ((1<<i)-1)) << (16-i) ); //accumulate rest R/65536
if (CPU.carry()) result++; //update result if rest overflows
}
fraction <<= 1; //next bit
}
if (rest < 0) result++; //roundoff
return result;
}

I think the method doesn't work...

Comments

  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2007-12-13 08:45
    CPU.carry() is a native method that returns true when the last math operation
    (add two postive numbers,·subtract two negative numbers) generates an overflow.
    If you have an example where umulf generates the wrong result, please post it.

    regards peter
Sign In or Register to comment.