diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2019-06-14 21:48:00 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2019-06-14 21:48:00 (GMT) |
commit | 15e17d01d57f28aa3ccb9adcc344937c4b5a34e0 (patch) | |
tree | 80050a4af1fcd9e60dbc7cf57462a7ed505974c9 /libtommath/bn_mp_sqrt.c | |
parent | e69d76af16939ec4327b1793f8a2cb358a141972 (diff) | |
parent | db7fa65dce753b80d5f2a87799aabd481e9144a2 (diff) | |
download | tcl-15e17d01d57f28aa3ccb9adcc344937c4b5a34e0.zip tcl-15e17d01d57f28aa3ccb9adcc344937c4b5a34e0.tar.gz tcl-15e17d01d57f28aa3ccb9adcc344937c4b5a34e0.tar.bz2 |
Latest libtommath's "develop" branch adapted for Tcl 8.6. And Tcl 8.6 adapted for changes in libtommath
Diffstat (limited to 'libtommath/bn_mp_sqrt.c')
-rw-r--r-- | libtommath/bn_mp_sqrt.c | 49 |
1 files changed, 18 insertions, 31 deletions
diff --git a/libtommath/bn_mp_sqrt.c b/libtommath/bn_mp_sqrt.c index 116fb14..aaeac1d 100644 --- a/libtommath/bn_mp_sqrt.c +++ b/libtommath/bn_mp_sqrt.c @@ -1,16 +1,7 @@ #include "tommath_private.h" #ifdef BN_MP_SQRT_C -/* LibTomMath, multiple-precision integer library -- Tom St Denis - * - * LibTomMath is a library that provides multiple-precision - * integer arithmetic as well as number theoretic functionality. - * - * The library was designed directly after the MPI library by - * Michael Fromberger but has been written from scratch with - * additional optimizations in place. - * - * SPDX-License-Identifier: Unlicense - */ +/* LibTomMath, multiple-precision integer library -- Tom St Denis */ +/* SPDX-License-Identifier: Unlicense */ #ifndef NO_FLOATING_POINT #include <math.h> @@ -20,9 +11,9 @@ #endif /* this function is less generic than mp_n_root, simpler and faster */ -int mp_sqrt(const mp_int *arg, mp_int *ret) +mp_err mp_sqrt(const mp_int *arg, mp_int *ret) { - int res; + mp_err err; mp_int t1, t2; #ifndef NO_FLOATING_POINT int i, j, k; @@ -36,7 +27,7 @@ int mp_sqrt(const mp_int *arg, mp_int *ret) } /* easy out */ - if (mp_iszero(arg) == MP_YES) { + if (MP_IS_ZERO(arg)) { mp_zero(ret); return MP_OKAY; } @@ -45,11 +36,11 @@ int mp_sqrt(const mp_int *arg, mp_int *ret) i = (arg->used / 2) - 1; j = 2 * i; - if ((res = mp_init_size(&t1, i+2)) != MP_OKAY) { - return res; + if ((err = mp_init_size(&t1, i+2)) != MP_OKAY) { + return err; } - if ((res = mp_init(&t2)) != MP_OKAY) { + if ((err = mp_init(&t2)) != MP_OKAY) { goto E2; } @@ -99,11 +90,11 @@ int mp_sqrt(const mp_int *arg, mp_int *ret) #else - if ((res = mp_init_copy(&t1, arg)) != MP_OKAY) { - return res; + if ((err = mp_init_copy(&t1, arg)) != MP_OKAY) { + return err; } - if ((res = mp_init(&t2)) != MP_OKAY) { + if ((err = mp_init(&t2)) != MP_OKAY) { goto E2; } @@ -113,24 +104,24 @@ int mp_sqrt(const mp_int *arg, mp_int *ret) #endif /* t1 > 0 */ - if ((res = mp_div(arg, &t1, &t2, NULL)) != MP_OKAY) { + if ((err = mp_div(arg, &t1, &t2, NULL)) != MP_OKAY) { goto E1; } - if ((res = mp_add(&t1, &t2, &t1)) != MP_OKAY) { + if ((err = mp_add(&t1, &t2, &t1)) != MP_OKAY) { goto E1; } - if ((res = mp_div_2(&t1, &t1)) != MP_OKAY) { + if ((err = mp_div_2(&t1, &t1)) != MP_OKAY) { goto E1; } /* And now t1 > sqrt(arg) */ do { - if ((res = mp_div(arg, &t1, &t2, NULL)) != MP_OKAY) { + if ((err = mp_div(arg, &t1, &t2, NULL)) != MP_OKAY) { goto E1; } - if ((res = mp_add(&t1, &t2, &t1)) != MP_OKAY) { + if ((err = mp_add(&t1, &t2, &t1)) != MP_OKAY) { goto E1; } - if ((res = mp_div_2(&t1, &t1)) != MP_OKAY) { + if ((err = mp_div_2(&t1, &t1)) != MP_OKAY) { goto E1; } /* t1 >= sqrt(arg) >= t2 at this point */ @@ -142,11 +133,7 @@ E1: mp_clear(&t2); E2: mp_clear(&t1); - return res; + return err; } #endif - -/* ref: $Format:%D$ */ -/* git commit: $Format:%H$ */ -/* commit time: $Format:%ai$ */ |