/* The end result is supposed to be a fixed-point number with FRAC_BITS bits of a fractional part, so we keep everything in the numerator shifted by that much as we compute  */
static int pcr_to_cbricg(const struct atm_qos *qos)
/* The end result is supposed to be a fixed-point number with FRAC_BITS bits of a fractional part, so we keep everything in the numerator shifted by that much as we compute  */
static int pcr_to_cbricg(const struct atm_qos *qos)
{
	int rounddown = 0;
	int x, icg, pcr = atm_pcr_goal(&qos->txtp);
	if (pcr == 0)
		return 0;
	if (pcr < 0) {
		rounddown = 1;
		pcr = -pcr;
	}
	x = pcr * 27;
	icg = (3125 << (9 + CBRICG_FRAC_BITS)) - (x << CBRICG_FRAC_BITS);
	if (rounddown)
		icg += x - 1;
	icg /= x;
	if (icg > CBRICG_MAX)
		icg = CBRICG_MAX;
	DPRINTK("pcr_to_cbricg: pcr=%d rounddown=%c icg=%d\n",
	    pcr, rounddown ? 'Y' : 'N', icg);
	return icg;
}