MulDiv函数

标签: , ,

MulDiv函数是Kernel32.dll提供的一个Windows API:

int MulDiv(
    _In_  int nNumber,
    _In_  int nNumerator,
    _In_  int nDenominator
);

把前两个32位数相乘,然后用得到的64位数除以第三个32位数,结果四舍五入后返回。如果除数为0或者发生了溢出,那么返回-1。

#include <stdio.h>
#include <windows.h>

//作者: Demon
//网站: https://demon.tw

int main()
{
    int a, b, c, d;

    a = 0x7fffffff;
    b = 0x7fffffff;
    c = 0x7fffffff;

    d = a * b / c;
    printf("%d\n", d);

    d = MulDiv(a, b, c);
    printf("%d\n", d);

    return 0;
}

可是如果返回-1的话,怎么区分是计算结果本身就是-1还是发生了错误呢?

赞赏

微信赞赏支付宝赞赏

随机文章:

  1. WinImage 8.50注册码
  2. PHP return语句
  3. 在线VBScript代码格式化工具VbsBeautifier
  4. Scrapy ImportError: DLL load failed: 操作系统无法运行 %1
  5. VbsEdit 5.6.1新增功能

留下回复