diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2017-10-02 15:22:27 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2017-10-02 15:22:27 (GMT) |
commit | afc317f97f0177e386ef463d2204be712252ceec (patch) | |
tree | b626ca6f62abaeff0393253fb9dbc4f0c3cfa5f5 /libtommath/bn_mp_n_root_ex.c | |
parent | 30f7e69b182d1267056ee2628a860891f6555aa3 (diff) | |
download | tcl-afc317f97f0177e386ef463d2204be712252ceec.zip tcl-afc317f97f0177e386ef463d2204be712252ceec.tar.gz tcl-afc317f97f0177e386ef463d2204be712252ceec.tar.bz2 |
'const'ify all libtommath functions, will appear in next libtommath version. See: pull request [https://github.com/libtom/libtommath/pull/88|88]libtommath
Diffstat (limited to 'libtommath/bn_mp_n_root_ex.c')
-rw-r--r-- | libtommath/bn_mp_n_root_ex.c | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/libtommath/bn_mp_n_root_ex.c b/libtommath/bn_mp_n_root_ex.c index 9546745..ca50649 100644 --- a/libtommath/bn_mp_n_root_ex.c +++ b/libtommath/bn_mp_n_root_ex.c @@ -25,10 +25,10 @@ * each step involves a fair bit. This is not meant to * find huge roots [square and cube, etc]. */ -int mp_n_root_ex(mp_int *a, mp_digit b, mp_int *c, int fast) +int mp_n_root_ex(const mp_int *a, mp_digit b, mp_int *c, int fast) { - mp_int t1, t2, t3; - int res, neg; + mp_int t1, t2, t3, a_; + int res; /* input must be positive if b is even */ if (((b & 1) == 0) && (a->sign == MP_NEG)) { @@ -48,8 +48,8 @@ int mp_n_root_ex(mp_int *a, mp_digit b, mp_int *c, int fast) } /* if a is negative fudge the sign but keep track */ - neg = a->sign; - a->sign = MP_ZPOS; + a_ = *a; + a_.sign = MP_ZPOS; /* t2 = 2 */ mp_set(&t2, 2); @@ -74,7 +74,7 @@ int mp_n_root_ex(mp_int *a, mp_digit b, mp_int *c, int fast) } /* t2 = t1**b - a */ - if ((res = mp_sub(&t2, a, &t2)) != MP_OKAY) { + if ((res = mp_sub(&t2, &a_, &t2)) != MP_OKAY) { goto LBL_T3; } @@ -100,7 +100,7 @@ int mp_n_root_ex(mp_int *a, mp_digit b, mp_int *c, int fast) goto LBL_T3; } - if (mp_cmp(&t2, a) == MP_GT) { + if (mp_cmp(&t2, &a_) == MP_GT) { if ((res = mp_sub_d(&t1, 1, &t1)) != MP_OKAY) { goto LBL_T3; } @@ -109,14 +109,11 @@ int mp_n_root_ex(mp_int *a, mp_digit b, mp_int *c, int fast) } } - /* reset the sign of a first */ - a->sign = neg; - /* set the result */ mp_exch(&t1, c); /* set the sign of the result */ - c->sign = neg; + c->sign = a->sign; res = MP_OKAY; |