fa0b81b54f97cf71f66fef311e1ecc93e7b84de5
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS system libraries
4 * FILE: dll/win32/kernel32/misc/muldiv.c
6 * PROGRAMMER: Casper S. Hornstrup
14 /***********************************************************************
17 * Result of multiplication and division
18 * -1: Overflow occurred or Divisor was 0
19 * FIXME! move to correct file
32 /* Find out if this will be a negative result */
33 Negative
= nNumber
^ nNumerator
^ nDenominator
;
35 /* Turn all the parameters into absolute values */
36 if (nNumber
< 0) nNumber
*= -1;
37 if (nNumerator
< 0) nNumerator
*= -1;
38 if (nDenominator
< 0) nDenominator
*= -1;
40 /* Calculate the result */
41 Result
.QuadPart
= Int32x32To64(nNumber
, nNumerator
) + (nDenominator
/ 2);
43 /* Now check for overflow */
44 if (nDenominator
> Result
.HighPart
)
46 /* Divide the product to get the quotient and remainder */
47 Result
.LowPart
= RtlEnlargedUnsignedDivide(*(PULARGE_INTEGER
)&Result
,
49 (PULONG
)&Result
.HighPart
);
51 /* Do the sign changes */
52 if ((LONG
)Result
.LowPart
>= 0)
54 return (Negative
>= 0) ? (LONG
)Result
.LowPart
: -(LONG
)Result
.LowPart
;