我需要计算
result = (dividend * factor) / divisor
Run Code Online (Sandbox Code Playgroud)
哪里
dividend: full range of int64_t values
factor: either a full range of uint32_t values or as a special case 2^32
divisor: positive values of int64_t
result: is guaranteed to fit in a int32_t
Run Code Online (Sandbox Code Playgroud)
我需要在没有微控制器上的任何库的普通C/C++中执行此操作.编译器支持int64_t和uint64_t类型; 很可能没有用于乘法或除法的硬件实现.目前我有uint32_t因子的解决方法,但我需要因子2 ^ 32的解决方案.