Question: is there `MulDiv`

```
WINBASEAPI
int
WINAPI
MulDiv(
    _In_ int nNumber,
    _In_ int nNumerator,
    _In_ int nDenominator
    );

```

in C# or an equivalent to it?

or should I Implement it ?

Edit: with out PInvoking!!

Answer: 
This api function dates back to Windows version 3, a 16-bit version of Windows. Quite possibly before, I'm not old enough. Where it was a bit difficult to get a C compiler to multiply two 16-bit numbers (two ints), get a 32-bit intermediate result and divide by a 16-bit number to get a 16 bit result. The operation was quite common, calculating a font size for example.

One of Microsoft's great burdens is that once they publish an api function, they have to maintain it *forever*, unless it is just grossly incompatible with necessary changes in the operating system. Nothing gross about MulDiv(), the *int* arguments did however get an automatic boost to 32-bits, making the function just about entirely unnecessary. But programs written for Win3 still compile, backcompat is sacred.

It was a bit of a mistake to burden the api with this, but the motivation was strong, pretty hard to cram a windowing system into 640 kilobytes. Exposing stuff that's already there because the OS needs it really helps shaving off the bytes. Other api functions like that are wprintf(), lstrcpyXxx(), etc. Core C runtime functions and *still* available today, even maintained through the switch to Unicode. An archeological record of Windows.

No point in pinvoking it, C# has no trouble doing this:

```
public static int MulDiv(int number, int numerator, int denominator) {
    return (int)(((long)number * numerator) / denominator);
}

```

Use the *checked* keyword if you want an overflow exception.
If you want to make it clear that you're going out of your way to handle the case where two 32-bit integers may yield a value larger than a 32-bit integer, you could use Math.BigMul, then just divide the result and cast it back to an integer. I see, as stated by other answers, .NET's support for 64-bit integers apparently provides all the benefits you'd need that MulDiv formerly would have (and then some).

```
int result = unchecked((int)(System.Math.BigMul(nNumber, nNumerator) / nDenominator));

```