//this class statically provides the methods for dealing with
//percent numbers (numbers between 0 and 1 represented by an int.

class PctInt {
    static final int BITS = 26;
    static final int ONE = (1 << BITS);
    static final int from_float(float a) {
	return (int)(a * ONE + 0.5f);
    }
    static final int divFI(int a, int b) {
	if (b < 0) {
	    b = -b;
	    a = -a;
	}
	if ((b >> FracInt.FRACBITS) == 0) return 1; //no div by zero.
	return (a / (b >> (FracInt.FRACBITS)));
    }
    static final int multFI(int a, int b) {
	//take out BITS/2 from each operand,
	//(but give the FracInt back FRACBITS 
	// to shift it into the right place)
	if ((b | a) > 0)
	    return ((a >> (BITS/2)) * 
		    (b >> (BITS-BITS/2-FracInt.FRACBITS)));
	else 
	    if ((b & a) < 0) {
		return ((-a >> (BITS/2)) * 
			(-b >> (BITS-BITS/2-FracInt.FRACBITS)));
	    } else {
		if (b < 0) 
		    return - ((a >> (BITS/2)) * 
			      (-b >> (BITS-BITS/2-FracInt.FRACBITS)));
		else 
		    return ((-a >> (BITS/2)) * 
			    (b >> (BITS-BITS/2-FracInt.FRACBITS)));
	    }
    }
    static final int mult(int a, int b) {
      if ((b | a) > 0)
	return (a >> (BITS/2)) * (b >> (BITS-BITS/2));
      else 
	if ((b & a) < 0) {
	  return (-a >> (BITS/2)) * (-b >> (BITS-BITS/2));
	} else {
	  if (b < 0) 
	    return - ((a >> (BITS/2)) * (-b >> (BITS-BITS/2)));
		else 
		  return ((-a >> (BITS/2)) * (b >> (BITS-BITS/2)));
	}
    }
}
