How can I descale x by n/d, when x*n overflows?
问题 My problem is limited to unsigned integers of 256 bits. I have a value x , and I need to descale it by the ratio n / d , where n < d . The simple solution is of course x * n / d , but the problem is that x * n may overflow. I am looking for any arithmetic trick which may help in reaching a result as accurate as possible. Dividing each of n and d by gcd(n, d) before calculating x * n / d does not guarantee success. Is there any process (iterative or other) which i can use in order to solve