YoushouldhavereceivedcopiesoftheGNUGeneralPublicLicenseandthe GNULesserGeneralPublicLicensealongwiththeGNUMPLibrary.Ifnot,
see https://www.gnu.org/licenses/. */
#include"gmp-impl.h"
/* Bit mask of "n" least significant bits of a limb. */ #define LOW_MASK(n) ((CNST_LIMB(1) << (n)) - 1)
/* MPZ_REALLOC(w) below is only when w!=u, so we can fetch PTR(u) here
nice and early */
up = PTR(u);
if ((usize ^ dir) < 0)
{ /* Round towards zero, means just truncate */
if (w == u)
{ /* if already smaller than limb_cnt then do nothing */ if (abs_usize <= limb_cnt) return;
wp = (mp_ptr) up;
} else
{
i = MIN (abs_usize, limb_cnt+1);
wp = MPZ_NEWALLOC (w, i);
MPN_COPY (wp, up, i);
/* if smaller than limb_cnt then only the copy is needed */ if (abs_usize <= limb_cnt)
{
SIZ(w) = usize; return;
}
}
} else
{ /* Round away from zero, means twos complement if non-zero */
/* if u!=0 and smaller than divisor, then must negate */ if (abs_usize <= limb_cnt) goto negate;
/* if non-zero low limb, then must negate */ for (i = 0; i < limb_cnt; i++) if (up[i] != 0) goto negate;
/* if non-zero partial limb, then must negate */ if ((up[limb_cnt] & LOW_MASK (cnt)) != 0) goto negate;
/* otherwise low bits of u are zero, so that's the result */
SIZ(w) = 0; return;
negate: /* twos complement negation to get 2**cnt-u */
wp = MPZ_REALLOC (w, limb_cnt+1);
up = PTR(u);
/* Ones complement */
i = MIN (abs_usize, limb_cnt+1);
ASSERT_CARRY (mpn_neg (wp, up, i)); for ( ; i <= limb_cnt; i++)
wp[i] = GMP_NUMB_MAX;
usize = -usize;
}
/* Mask the high limb */
high = wp[limb_cnt];
high &= LOW_MASK (cnt);
wp[limb_cnt] = high;
/* Strip any consequent high zeros */ while (high == 0)
{
limb_cnt--; if (limb_cnt < 0)
{
SIZ(w) = 0; return;
}
high = wp[limb_cnt];
}
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.