小编p.g*_*.g.的帖子

在64位有符号整数上组合乘除运算,无溢出

我需要计算

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的解决方案.

c algorithm biginteger division bignum

9
推荐指数
1
解决办法
230
查看次数

标签 统计

algorithm ×1

biginteger ×1

bignum ×1

c ×1

division ×1