ReactOS 0.4.15-dev-7924-g5949c20
muldiv.c
Go to the documentation of this file.
1/*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS system libraries
4 * FILE: dll/win32/kernel32/wine/muldiv.c
5 * PURPOSE:
6 * PROGRAMMER: Casper S. Hornstrup
7 * Gunnar Andre Dalsnes
8 * UPDATE HISTORY:
9 * Created 06/12/2002
10 */
11
12#include <k32.h>
13
14/***********************************************************************
15 * MulDiv (KERNEL32.@)
16 * RETURNS
17 * Result of multiplication and division
18 * -1: Overflow occurred or Divisor was 0
19 * FIXME! move to correct file
20 *
21 * @implemented
22 */
23INT
25MulDiv(INT nNumber,
26 INT nNumerator,
27 INT nDenominator)
28{
30 LONG Negative;
31
32 /* Find out if this will be a negative result */
33 Negative = nNumber ^ nNumerator ^ nDenominator;
34
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;
39
40 /* Calculate the result */
41 Result.QuadPart = Int32x32To64(nNumber, nNumerator) + (nDenominator / 2);
42
43 /* Now check for overflow */
44 if (nDenominator > Result.HighPart)
45 {
46 /* Divide the product to get the quotient and remainder */
48 (ULONG)nDenominator,
49 (PULONG)&Result.HighPart);
50
51 /* Do the sign changes */
52 if ((LONG)Result.LowPart >= 0)
53 {
54 return (Negative >= 0) ? (LONG)Result.LowPart : -(LONG)Result.LowPart;
55 }
56 }
57
58 /* Return overflow */
59 return - 1;
60}
61
NTSYSAPI UINT WINAPI RtlEnlargedUnsignedDivide(ULONGLONG, UINT, UINT *)
INT WINAPI MulDiv(INT nNumber, INT nNumerator, INT nDenominator)
Definition: muldiv.c:25
#define Int32x32To64(a, b)
long LONG
Definition: pedump.c:60
uint32_t * PULONG
Definition: typedefs.h:59
int32_t INT
Definition: typedefs.h:58
uint32_t ULONG
Definition: typedefs.h:59
#define WINAPI
Definition: msvc.h:6
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:409