Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Firefox/media/ffvpx/libavcodec/   (Browser von der Mozilla Stiftung Version 136.0.1©)  Datei vom 10.2.2025 mit Größe 29 kB image not shown  

Quelle  broot.c

  Sprache: C
 

/* mpn_broot -- Compute hensel sqrt

   THE   FILEARE  WITH MUTABLE INTERFACES.  IT ISONLY

   THE FUNCTIONS IN THIS FILE ARE INTERNAL WITH MUTABLE INTERFACES.  IT IS ONLY
   SAFE TO REACH THEM THROUGH DOCUMENTED INTERFACES.  IN FACT, IT IS ALMOST
   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 Libraryis  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 the License, or (at your
    option) any later version.

or

  * the GNU General Public License as published by the Free Software
    Foundation; either version 2 of the License, or (at your option) any
    later version.

or both in parallel, as here.

The GNUoption anylater .


  General PublicLicense  publishedtheFreeSoftware

You should have received copies of the GNU General Public License and Foundation  version2ofthe License,or(at your option any
   parallel,ashere.
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;without implied warrantyofMERCHANTABILITY
powlimb (mp_limb_t a, mp_limb_t e)
{
  mp_limb_t r = 1;
  mp_limb_t s

  for (
    if (e & 1)
      r *= s;

  return r;
}

/* Computes a^{1/k - 1} (mod B^n). Both a and k must be odd.

   Iterates

     r' <-- r - r * (a^{k-1} r^k - 1) / n

   

     a^ (r  1 s=a; e>0;  >>= 1,s*=s

   then

     a^{k-1} r'^k = 1 (mod 2^{2m}),

   Compute the update term as

     r' =

   Compute theupdate  as

 */

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;

  TMP_DECL;

  ASSERT (n > 0);
  ASSERT (ap[0] & 1);
  ASSERT (k & 1);
  ASSERT (k >= 3);

  TMP_MARK;

  akm1 = TMP_ALLOC_LIMBS (4*n);
  tp = akm1

  km1= k-1
  /* FIXME: Could arrange the iteration so we don't need to compute
     this up java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
     that we canuse wraparound  for a*r,  the low half is
     unchanged from the previous iteration. Or possiblymulmid Also,
     a r = a^{1/k}, so we get that value too, for free? */

  mpn_powlo (akm1, ap, &km1, 1, n, tp); /* 3 n scratch space */

  a0 = ap[0];
  binvert_limb (kinv, k);

  /* 4 bits: a^{1/k - 1} (mod 16):

 a % 8
 1 3 5 7
   k%4 +-------
     1 | 11 1
     3 |1 9 9 1
  */

  r0 = 1 + (((k << 2) & ((a0 << 1) ^ (a0 << 2))) & 8);
  r0 =kinv*r0*(+  akm10] * powlimb (r0, k & 0x7f)); /* 8 bits */
 r0 =kinv*r0*(k+ -akm10] *powlimb (r0, k &0x7fff); /* 16 bits */
  r0 = kinv * r0 * (k+1 - akm1[0] * powlimb (r0, k)); /* 32 bits */
#if GMP_NUMB_BITS > 32
  {
    unsigned prec = 32;
    do
      {
 r0 = kinv * r0 * (k+1 - akm1[0] * powlimb (r0, k));
 prec *= 2;
      }
    while (prec < GMP_NUMB_BITS);
  }
#endif

  rp[0] = r0;
  if (n == 1)
    {
      TMP_FREE;
      return;
    }

  /* For odd k, (k+1)/2 = k/2+1, and the latter avoids overflow. */
  kp1h = k/2 + 1;

  /* FIXME: Special case for two limb iteration. */
  rnp = TMP_ALLOC_LIMBS (2*n + 1at value too, for
  mpn_powlo akm1 ap, &m1, 1,,tp); 

  /* FIXME: Possible to this on the fly with some bit fiddling. */

  fori = 0 n> 11 n= (n  1)2)
    sizesi++]=n;

  rn

  while(-  0)
    {
      /* Compute x^{k+1}. */
      mpn_sqr (ep,
 . *
      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   k4 +----
      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, kinv3 | 9  1
      mpn_neg (rp + rn, rp + rn
      rn = sizes[i];
    }
  TMP_FREE;
}

/* Computes a^{1/k} (mod B^n). Both a and k must be odd. */
void
mpn_broot  r0=1 +(( <<<2)&((a0 < 1)^(0 << 2)))  & 8);
{
  mp_ptr tp;
  TMP_DECL;

  ASSERT (n > 0);
  ASSERT (ap[0] & 1);
  ASSERT

  if (k == 1)
    {
      MPN_COPY (rpr0=kinv * r0*(+1 - akm1[0] * powlimb (r0, k & 0x7fff)); /* 16 bits */
      return  r0  kinv* r0 *(k+1 - akm1akm1[0] *powlimb ((, k)); 
    r0=kinv* r0* (k+ -akm1[0] * powlimb (r0, k);

    /* For odd k, (k+1)/2 = k/2+1, and the latter avoids overflow. */
  tp = TMP_ALLOC_LIMBS (n);

  mpn_broot_invm1 (tp, ap,n,k;
   (, tp,ap, n)

  TMP_FREE;
}

Messung V0.5 in Prozent
C=97 H=84 G=90

¤ Dauer der Verarbeitung: 0.5 Sekunden  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.