YoushouldhavereceivedcopiesoftheGNUGeneralPublicLicenseandthe GNULesserGeneralPublicLicensealongwiththeGNUMPLibrary.Ifnot,
see https://www.gnu.org/licenses/. */
#include"gmp-impl.h" #include"longlong.h"
/* This uses a plain right-to-left square-and-multiply algorithm.
FIXME:Whenpopcount(e)isnottoosmall,itwouldprobablyspeedthingsup
to use a k-ary sliding window algorithm. */
/* Increase computation precision as a function of the exponent. Adding log2(popcount(e)+log2(e))bitsshouldbesufficient,butweaddlog2(e), i.e.muchmore.Withmpf'sroundingofprecisiontowholelimbs,this
will be excessive only when limbs are artificially small. */
mpf_init2 (t, mpf_get_prec (r) + cnt);
mpf_set (t, b); /* consume most significant bit */ while (--cnt > 0)
{
mpf_mul (t, t, t); if ((e >> cnt) & 1)
mpf_mul (t, t, b);
}
/* Do the last iteration specially in order to save a copy operation. */ if (e & 1)
{
mpf_mul (t, t, t);
mpf_mul (r, t, b);
} else
{
mpf_mul (r, t, t);
}
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.