diff options
author | Kevin B Kenny <kennykb@acm.org> | 2006-11-30 23:33:49 (GMT) |
---|---|---|
committer | Kevin B Kenny <kennykb@acm.org> | 2006-11-30 23:33:49 (GMT) |
commit | 2c384db27cc46862fb7a386ba652980bd4accd35 (patch) | |
tree | 769ac2d1fb59eea7821f82cc0aa362fc3e040a95 /libtommath/bn_mp_sqrt.c | |
parent | 8469dcdb5c8b3e1f28bbbee7974cbd458af50bea (diff) | |
download | tcl-2c384db27cc46862fb7a386ba652980bd4accd35.zip tcl-2c384db27cc46862fb7a386ba652980bd4accd35.tar.gz tcl-2c384db27cc46862fb7a386ba652980bd4accd35.tar.bz2 |
fixed bug in floating point initial approximation that caused convergence failure
Diffstat (limited to 'libtommath/bn_mp_sqrt.c')
-rw-r--r-- | libtommath/bn_mp_sqrt.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/libtommath/bn_mp_sqrt.c b/libtommath/bn_mp_sqrt.c index 72a9ff5..f6e65dc 100644 --- a/libtommath/bn_mp_sqrt.c +++ b/libtommath/bn_mp_sqrt.c @@ -68,12 +68,18 @@ int mp_sqrt(mp_int *arg, mp_int *ret) dig = (mp_digit) ldexp(d, -DIGIT_BIT); if (dig) { t1.used = i+2; - t1.dp[i+1] = dig; d -= ldexp((double) dig, DIGIT_BIT); + if (d != 0,0) { + t1.dp[i+1] = dig; + t1.dp[i] = ((mp_digit) d) - 1; + } else { + t1.dp[i+1] = dig-1; + t1.dp[i] = MP_DIGIT_MAX; + } } else { t1.used = i+1; + t1.dp[i] = ((mp_digit) d) - 1; } - t1.dp[i] = (mp_digit) d; #else @@ -119,5 +125,5 @@ E2: mp_clear(&t1); #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/bn_mp_sqrt.c,v $ */ -/* $Revision: 1.2 $ */ -/* $Date: 2005/12/27 17:39:02 $ */ +/* $Revision: 1.3 $ */ +/* $Date: 2006/11/30 23:33:49 $ */ |