[WINCE] MulDiv 함수 구현

by digipine posted Oct 29, 2017
?

Shortcut

PrevPrev Article

NextNext Article

ESCClose

Larger Font Smaller Font Up Down Go comment Print

기본적은 WinCE API 에서는 MulDiv 함수가 제공되지 않습니다.
이 함수는 화면의 비율이나 DPI 관련 부분을 계산하기에 편리하게 쓰이는데

lfHeight = -MulDiv(PointSize, GetDeviceCaps(hDC, LOGPIXELSY), 72);


와 같이 쓰면 편리하지요.

그래서 다음과 같이 구현해 보았습니다.


int MulDiv(int a, int b, int c)
{
    int nMul = a * b,
        nMod = nMul % c,
        nRes = nMul / c;

    if(nMod >= c / 2)    // Round up if >= 0.5
        nRes++;
    return nRes;
}


좀더 큰 int를 구현하려면  __int64 타입일 사용하시면 됩니다.
TAG •

Articles

1 2 3