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;
}