Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenmuldiv.c
Go to the documentation of this file.
00001 /* $Id: muldiv.c 37829 2008-12-03 17:33:13Z dgorbachev $ 00002 * 00003 * COPYRIGHT: See COPYING in the top level directory 00004 * PROJECT: ReactOS system libraries 00005 * FILE: dll/win32/kernel32/misc/muldiv.c 00006 * PURPOSE: 00007 * PROGRAMMER: Casper S. Hornstrup 00008 * Gunnar Andre Dalsnes 00009 * UPDATE HISTORY: 00010 * Created 06/12/2002 00011 */ 00012 00013 #include <k32.h> 00014 00015 00016 /*********************************************************************** 00017 * MulDiv (KERNEL32.@) 00018 * RETURNS 00019 * Result of multiplication and division 00020 * -1: Overflow occurred or Divisor was 0 00021 * FIXME! move to correct file 00022 * 00023 * @implemented 00024 */ 00025 INT 00026 WINAPI 00027 MulDiv(INT nNumber, 00028 INT nNumerator, 00029 INT nDenominator) 00030 { 00031 LARGE_INTEGER Result; 00032 LONG Negative; 00033 00034 /* Find out if this will be a negative result */ 00035 Negative = nNumber ^ nNumerator ^ nDenominator; 00036 00037 /* Turn all the parameters into absolute values */ 00038 if (nNumber < 0) nNumber *= -1; 00039 if (nNumerator < 0) nNumerator *= -1; 00040 if (nDenominator < 0) nDenominator *= -1; 00041 00042 /* Calculate the result */ 00043 Result.QuadPart = Int32x32To64(nNumber, nNumerator) + (nDenominator / 2); 00044 00045 /* Now check for overflow */ 00046 if (nDenominator > Result.HighPart) 00047 { 00048 /* Divide the product to get the quotient and remainder */ 00049 Result.LowPart = RtlEnlargedUnsignedDivide(*(PULARGE_INTEGER)&Result, 00050 (ULONG)nDenominator, 00051 (PULONG)&Result.HighPart); 00052 00053 /* Do the sign changes */ 00054 if ((LONG)Result.LowPart >= 0) 00055 { 00056 return (Negative >= 0) ? (LONG)Result.LowPart : -(LONG)Result.LowPart; 00057 } 00058 } 00059 00060 /* Return overflow */ 00061 return - 1; 00062 } 00063 Generated on Sat May 26 2012 04:23:05 for ReactOS by
1.7.6.1
|