7 /***********************************************************************
10 * Result of multiplication and division
11 * -1: Overflow occurred or Divisor was 0
12 * FIXME! move to correct file
21 #if SIZEOF_LONG_LONG >= 8
24 if (!nDivisor) return -1;
26 /* We want to deal with a positive divisor to simplify the logic. */
29 nMultiplicand = - nMultiplicand;
33 /* If the result is positive, we "add" to round. else, we subtract to round. */
34 if ( ( (nMultiplicand < 0) && (nMultiplier < 0) ) ||
35 ( (nMultiplicand >= 0) && (nMultiplier >= 0) ) )
36 ret = (((long long)nMultiplicand * nMultiplier) + (nDivisor/2)) / nDivisor;
38 ret = (((long long)nMultiplicand * nMultiplier) - (nDivisor/2)) / nDivisor;
40 if ((ret > 2147483647) || (ret < -2147483647)) return -1;
43 if (!nDivisor) return -1;
45 /* We want to deal with a positive divisor to simplify the logic. */
48 nMultiplicand = - nMultiplicand;
52 /* If the result is positive, we "add" to round. else, we subtract to round. */
53 if ( ( (nMultiplicand < 0) && (nMultiplier < 0) ) ||
54 ( (nMultiplicand >= 0) && (nMultiplier >= 0) ) )
55 return ((nMultiplicand * nMultiplier) + (nDivisor/2)) / nDivisor;
57 return ((nMultiplicand * nMultiplier) - (nDivisor/2)) / nDivisor;