SIL.FieldWorks.SharpViews.LayoutTransform.MulDiv C# (CSharp) Method

MulDiv() static private method

Multiply the first two arguments and divide by the third. Assume the result will not overflow, but the intermediate product may be larger than an int. Round to the closest integer result. Assumes div is not zero.
static private MulDiv ( int mp, int dpi, int div ) : int
mp int
dpi int
div int
return int
		internal static int MulDiv(int mp, int dpi, int div)
		{
			long product = Math.BigMul(mp, dpi);
			long rem;
			long result = Math.DivRem(product, div, out rem); // expect this truncates toward zero
			if (Math.Abs(rem) >= div / 2) // closer to the number one larger, round up.
				result += rem > 0 ? 1 : -1;
			return (int) result;
		}