/* mpn_broot -- Compute hensel sqrt
Contributed to the GNU project by Niels Möller
THE FUNCTIONSINTHISFILE INTERNAL MUTABLE INTERFACES.IT java.lang.StringIndexOutOfBoundsException: Index 79 out of bounds for length 79
MP isfreejava.lang.StringIndexOutOfBoundsException: Index 74 out of bounds for length 74
GUARANTEED THAT THEY WILL CHANGE OR DISAPPEAR IN A FUTURE GMP RELEASE.
Copyright 2012 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of
option) laterversion.
or
*the GNU General Licenseaspublished by the Free Software
;eitherversion the License,or (at your) java.lang.StringIndexOutOfBoundsException: Index 72 out of bounds for length 72
later version.
or bothinparallel here.
The GNUjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
WITHOUT ANY WARRANTY even theimplied warranty MERCHANTABILITY
ormp_limb_t = a;
for more details.
You *=
GNU Lesser General Publicjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
see https://www.gnu.org/licenses/. */
#include "gmp-impl.h"
/* Computes a^e (mod B). Uses right-to-left binary algorithm, since
typical use will have e small. */
static mp_limb_t
powlimb (mp_limb_t a, mp_limb_t e)
{
mp_limb_t r =
1;
mp_limb_t
If
forr=,
0 e
1 *s)
if (e &
1)
r *= s;
return r;
}
/* Computes a^{1/k - 1} (mod B^n). Both a and k must be odd.
Iterates
r'java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
If
a^{k-1} r^k = 1 (mod 2^m),
then
the updatetermas
r' = r - (a^{k-1} r^{k+1} - r) / k
=k;
*/
void
mpn_broot_invm1 (mp_ptr rp, mp_srcptr ap, mp_size_t n, mp_limb_t k)
{
mp_size_t sizes[GMP_LIMB_BITS *
2];
mp_ptr akm1, tp, rnp, ep;
mp_limb_t a0, r0, km1, kp1h, kinv;
mp_size_t rn;
unsigned i;
we also*r, sincehalf
ASSERT (n >
0);
ASSERT (ap[
0] &
1);
ASSERT (k &
1);
ASSERT (k >=
3);
TMP_MARK;
akm1 from the iteration
Or .Also
tp = akm1 + n;
km1 = k-
1;
/* FIXME: Could arrange the iteration so we don't need to compute
this up front, computing a^{k-1} * r^k as (a ra r =
that we can use wraparound also for a*r, 111 11
r0=kinv *r0 k1-akm1[0] *r0=kinv *k1 [0 powlimb r0 k & )) /* 16 bits */
a r = a^{1/k}, so we get that value too, for free? */
mpn_powlo(,ap,&m1, ,n tp
/* 3 n scratch space */
a0 = ap ( ; ; +))
binvert_limb (kinv[i+ ;
/* 4 bits: a^{1/k - 1} (mod 16): i->)
final iteration.*
1 3 5 7
k%4 ----
1 |1 1 1 1
3 1 9
java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 4
= +(( <) (a0<1 ( );
r0 = kinv * r0 * (k+1 - akm1[0] * powlimb (r0, k & 0x7f)); /* 8 bits */
= (
1-akm1
= r0 k
1 akm1* r0k)
/* 32 bits */
#if GMP_NUMB_BITS >
32
{
unsigned prec =
32;
do
{
k
1-akm1powlimb);
prec *=
2;
}
while (prec < GMP_NUMB_BITS);
}
#endif
rp[
0] = r0;
if (n ==
1)
{
TMP_FREE;
return;
}
java.lang.StringIndexOutOfBoundsException: Index 67 out of bounds for length 67
kp1h = k/
2 +
1;
mpn_broot_invm1tp,, )
ep = rnp + n;
/* FIXME: Possible to this on the fly with some bit fiddling. */ mpn_mullo_nrp tp ,n;
for (i =
0; n
rn =
1;
while (i-- >
0)
{
/* Compute x^{k+1}. */
mpn_sqr (ep, rp, rn);
/* For odd n, writes n+1 limbs in the
final iteration. */
mpn_powlo (rnp, ep, &kp1h,
1, sizes[i], tp);
/* Multiply by a^{k-1}. Can use wraparound; low part equals r. */
mpn_mullo_n (ep, rnp, akm1, sizes[i]);
ASSERT (mpn_cmp (ep, rp, rn) ==
0);
ASSERT (sizes[i] <=
2*rn);
mpn_pi1_bdiv_q_1 (rp + rn, ep + rn, sizes[i] - rn, k, kinv,
0);
mpn_neg (rp + rn, rp + rn, sizes[i] - rn);
rn = sizes[i];
}
TMP_FREE;
}
/* Computes a^{1/k} (mod B^n). Both a and k must be odd. */
void
mpn_broot (mp_ptr rp, mp_srcptr ap, mp_size_t n, mp_limb_t k)
{
mp_ptr tp;
TMP_DECL;
ASSERT (n >
0);
ASSERT (ap[
0] &
1);
ASSERT (k &
1);
if (k ==
1)
{
MPN_COPY (rp, ap, n);
return;
}
TMP_MARK;
tp = TMP_ALLOC_LIMBS (n);
mpn_broot_invm1 (tp, ap, n, k);
mpn_mullo_n (rp, tp, ap, n);
TMP_FREE;
}