| Deep BlueVBScriptWMIPHPC语言JavaScriptWindows API路由器Windows函数Python |
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
//网站: http://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还是发生了错误呢?
|