How do I compute the multiplication of two uint256
so the result doesn't overflow?
In the end, this multiplication is an intermediate step within a larger operation, in case this extra piece of info helps.
Fyi, I'm not looking to change the order of the operations nor remove any padding.
uint256 a = 10864869065949319007600000000000000000000;
uint256 b = 3300000000000000000000000000000000000000;
uint256 c = 10859952502829164007600000000000000000000;
uint256 result = (a * b) / c;
The overflow occurs in (a * b)
.
Assembly is more than welcomed if it produces the expected result. Thanks!
c
and then multiply to get the result likeresult = (((a * 1e18) / c) * ((b * 1e18) / c)) / 1e18
. But, you've mentioned that you're not looking to change the order of the operations, therefore it's not valid in that case.