summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortege <tege@gmplib.org>2002-10-18 17:09:11 +0200
committertege <tege@gmplib.org>2002-10-18 17:09:11 +0200
commit95810e7779198fc8b199c8ad58e0af5ffb7e268c (patch)
treedf80f83f955e86a649cc839c39fc9fcfc0adec6f
parent61837fdb23953dd4aceefddcab07237444571760 (diff)
downloadgmp-95810e7779198fc8b199c8ad58e0af5ffb7e268c.tar.gz
Avoid overflow problem when n is huge.
-rw-r--r--mpn/generic/rootrem.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/mpn/generic/rootrem.c b/mpn/generic/rootrem.c
index 168baa9e5..bcfeaed82 100644
--- a/mpn/generic/rootrem.c
+++ b/mpn/generic/rootrem.c
@@ -70,7 +70,7 @@ mpn_rootrem (mp_ptr rootp, mp_ptr remp,
count_leading_zeros (cnt, up[un - 1]);
unb = un * GMP_NUMB_BITS - cnt + GMP_NAIL_BITS;
- xnb = (unb + nth - 1) / nth;
+ xnb = (unb - 1) / nth + 1;
if (xnb == 1)
{
if (remp == NULL)
@@ -114,8 +114,8 @@ mpn_rootrem (mp_ptr rootp, mp_ptr remp,
adj = n_valid_bits - 1;
/* Newton loop. Converges downwards towards root(U,nth). Currently we use
- full precision from iteration 1. Clearly, we should use just n_valid_bits
- of precision in each step, and thus save most of the computations. */
+ full precision from iteration 1. Clearly, we should use just n_valid_bits
+ of precision in each step, and thus save most of the computations. */
while (n_valid_bits <= xnb)
{
mp_limb_t cy;