YoushouldhavereceivedcopiesoftheGNUGeneralPublicLicenseandthe GNULesserGeneralPublicLicensealongwiththeGNUMPLibrary.Ifnot,
see https://www.gnu.org/licenses/. */
#include"gmp-impl.h"
/* How many special cases? Minimum is 2: 0 and 1; *also3{0,1,2}and5{0,1,2,3,4}areimplemented.
*/ #define APARTAJ_KALKULOJ 2
/* Whether to use (1) or not (0) the function mpz_bin_uiui whenever *theoperandsfit.
*/ #define UZU_BIN_UIUI 0
/* Whether to use a shortcut to precompute the product of four *elements(1),orprecomputeonlytheproductofacouple(0). * *Inbothcasestheprecomputedproductisthenupdatedwithsome *linearoperationstoobtaintheproductofthenextfour(1) *[ortwo(0)]operands.
*/ #define KVAROPE 1
staticvoid
posmpz_init (mpz_ptr r)
{
mp_ptr rp;
ASSERT (SIZ (r) > 0);
rp = SIZ (r) + MPZ_REALLOC (r, SIZ (r) + 2);
*rp = 0;
*++rp = 0;
}
/* Equivalent to mpz_add_ui (r, r, in), but faster when
0 < SIZ (r) < ALLOC (r) and limbs above SIZ (r) contain 0. */ staticvoid
posmpz_inc_ui (mpz_ptr r, unsignedlong in)
{ #if BITS_PER_ULONG > GMP_NUMB_BITS
mpz_add_ui (r, r, in); #else
ASSERT (SIZ (r) > 0);
MPN_INCR_U (PTR (r), SIZ (r) + 1, in);
SIZ (r) += PTR (r)[SIZ (r)]; #endif
}
/* Equivalent to mpz_sub_ui (r, r, in), but faster when
0 < SIZ (r) and we know in advance that the result is positive. */ staticvoid
posmpz_dec_ui (mpz_ptr r, unsignedlong in)
{ #if BITS_PER_ULONG > GMP_NUMB_BITS
mpz_sub_ui (r, r, in); #else
ASSERT (mpz_cmp_ui (r, in) >= 0);
MPN_DECR_U (PTR (r), SIZ (r), in);
SIZ (r) -= (PTR (r)[SIZ (r)-1] == 0); #endif
}
/* Equivalent to mpz_tdiv_q_2exp (r, r, 1), but faster when
0 < SIZ (r) and we know in advance that the result is positive. */ staticvoid
posmpz_rsh1 (mpz_ptr r)
{
mp_ptr rp;
mp_size_t rn;
rn = SIZ (r);
rp = PTR (r);
ASSERT (rn > 0);
mpn_rshift (rp, rp, rn, 1);
SIZ (r) -= rp[rn - 1] == 0;
}
/* Computes (n+1)(n+2)...(n+k)/2^(k/2 +k/4) using the helper function rek_raising_fac4,andexploitinganideainspiredbyapieceof codethatFredrikJohanssonwroteandbyacommentbyNielsMöller.
/* This is a poor implementation. Look at bin_uiui.c for improvement ideas. Infactconsidercallingmpz_bin_uiui()whentheargumentsfit,leaving thecodehereonlyforbign.
Theidentitybin(n,k)=(-1)^k*bin(-n+k-1,k)canbefoundinKnuthvol
1 section 1.2.6 part G. */
if (SIZ (n) < 0)
{ /* bin(n,k) = (-1)^k * bin(-n+k-1,k), and set ni = -n+k-1 - k = -n-1 */
mpz_init (ni);
mpz_add_ui (ni, n, 1L);
mpz_neg (ni, ni);
negate = (k & 1); /* (-1)^k */
} else
{ /* bin(n,k) == 0 if k>n
(no test for this under the n<0 case, since -n+k-1 >= k there) */ if (mpz_cmp_ui (n, k) < 0)
{
SIZ (r) = 0; return;
}
/* set ni = n-k */
mpz_init (ni);
mpz_sub_ui (ni, n, k);
negate = 0;
}
/* Now wanting bin(ni+k,k), with ni positive, and "negate" is the sign (0
for positive, 1 for negative). */
/* Rewrite bin(n,k) as bin(n,n-k) if that is smaller. In this case it's whetherni+k-k<kmeaningni<k,andifsochangetodenominatorni+k-k
= ni, and new ni of ni+k-ni = k. */ if (mpz_cmp_ui (ni, k) < 0)
{ unsignedlong tmp;
tmp = k;
k = mpz_get_ui (ni);
mpz_set_ui (ni, tmp);
}
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.