UnsignedIntMath.java problem in umulf fonction
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...
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
(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