Lines Matching refs:digit

81  * being an internal Python int digit, in base BASE).
111 * multiple of a long digit's max bit length (15 or 30 so far).
142 ((PY_SSIZE_T_MAX - offsetof(PyLongObject, ob_digit))/sizeof(digit))
153 /* Fast operations for single digit integers (including zero)
154 * assume that there is always at least one digit present. */
157 sizeof(digit)*size. Previous incarnations of this code used
162 ndigits*sizeof(digit));
209 digit abs_x = x < 0 ? -x : x;
242 digit *p = v->ob_digit;
247 t & PyLong_MASK, twodigits, digit);
315 digit *p = v->ob_digit;
319 *p++ = (digit)(t & PyLong_MASK);
342 digit *p = v->ob_digit; \
344 *p++ = (digit)((ival) & PyLong_MASK); \
420 digit bits = (digit)frac;
775 bit_length_digit(digit x)
777 // digit can be larger than unsigned long, but only PyLong_SHIFT bits
780 "digit is larger than unsigned long");
797 digit msd = v->ob_digit[ndigits - 1];
867 8*numsignificantbytes bits, and each Python int digit has
904 /* There's enough to fill a Python digit. */
906 v->ob_digit[idigit] = (digit)(accum & PyLong_MASK);
916 v->ob_digit[idigit] = (digit)accum;
935 digit carry; /* for computing 2's-comp */
966 It's crucial that every Python digit except for the MSD contribute
975 digit thisdigit = v->ob_digit[i];
986 /* The most-significant digit may be (probably is) at least
992 digit s = do_twos_comp ? thisdigit ^ PyLong_MASK : thisdigit;
1015 assert(carry == 0); /* else do_twos_comp and *every* digit was 0 */
1142 digit *p = v->ob_digit;
1146 *p++ = (digit)(t & PyLong_MASK);
1185 digit *p = v->ob_digit;
1189 *p++ = (digit)(t & PyLong_MASK);
1528 /* x[0:m] and y[0:n] are digit vectors, LSD first, m >= n required. x[0:n]
1532 static digit
1533 v_iadd(digit *x, Py_ssize_t m, digit *y, Py_ssize_t n)
1536 digit carry = 0;
1554 /* x[0:m] and y[0:n] are digit vectors, LSD first, m >= n required. x[0:n]
1558 static digit
1559 v_isub(digit *x, Py_ssize_t m, digit *y, Py_ssize_t n)
1562 digit borrow = 0;
1580 /* Shift digit vector a[0:m] d bits left, with 0 <= d < PyLong_SHIFT. Put
1583 static digit
1584 v_lshift(digit *z, digit *a, Py_ssize_t m, int d)
1587 digit carry = 0;
1592 z[i] = (digit)acc & PyLong_MASK;
1593 carry = (digit)(acc >> PyLong_SHIFT);
1598 /* Shift digit vector a[0:m] d bits right, with 0 <= d < PyLong_SHIFT. Put
1601 static digit
1602 v_rshift(digit *z, digit *a, Py_ssize_t m, int d)
1605 digit carry = 0;
1606 digit mask = ((digit)1 << d) - 1U;
1611 carry = (digit)acc & mask;
1612 z[i] = (digit)(acc >> d);
1617 /* Divide long pin, w/ size digits, by non-zero digit n, storing quotient
1626 generated by the compiler despite us working with 30-bit digit values.
1638 static digit
1639 inplace_divrem1(digit *pout, digit *pin, Py_ssize_t size, digit n)
1641 digit remainder = 0;
1647 digit quotient;
1648 quotient = (digit)(dividend / n);
1656 /* Divide an integer by a digit, returning both the quotient
1661 divrem1(PyLongObject *a, digit n, digit *prem)
1674 /* Remainder of long pin, w/ size digits, by non-zero digit n,
1677 static digit
1678 inplace_rem1(digit *pin, Py_ssize_t size, digit n)
1685 return (digit)rem;
1688 /* Get the remainder of an integer divided by a digit, returning
1693 rem1(PyLongObject *a, digit n)
1717 digit *pout, *pin, rem, tenpow;
1730 /* quick and dirty pre-check for overflowing the decimal digit limit,
1776 digit hi = pin[i];
1779 hi = (digit)(z / _PyLong_DECIMAL_BASE);
1780 pout[j] = (digit)(z - (twodigits)hi *
1793 /* pout should have at least one digit, so that the case when a = 0
1851 /* pout[size-1]: always produce at least one decimal digit */ \
2138 /* Table of digit values for 8-bit string -> integer conversion.
2143 * base B digit iff _PyLong_DigitValue[Py_CHARPyLong_MASK(c)] < B.
2164 /* *str points to the first digit in a string of base `base` digits. base
2166 * non-digit (which may be *str!). A normalized int is returned.
2186 digit *pdigit;
2243 *pdigit++ = (digit)(accum & PyLong_MASK);
2252 *pdigit++ = (digit)accum;
2344 is B**N-1. Consequently, if we have an N-digit input in base B, the worst-
2362 must fit in a single Python digit. The second is effectively the input
2385 Waste isn't a problem: provided the first input digit isn't 0, the difference
2388 one allocated Python digit can remain unused on that count. If
2417 new Python digit is added, and copies the whole thing to a larger int if not.
2420 just 1 digit at the start, so that the copying code was exercised for every
2421 digit beyond the first.
2429 digit *pz, *pzstop;
2516 * digit in base `convmultmax`.
2528 c = (digit)_PyLong_DigitValue[Py_CHARMASK(*str++)];
2555 *pz = (digit)(c & PyLong_MASK);
2562 *pz = (digit)c;
2576 sizeof(digit) * size_z);
2579 z->ob_digit[size_z] = (digit)c;
2724 digit rem = 0;
2814 digit wm1, wm2, carry, q, r, vtop, *v0, *vk, *w0, *ak;
2822 digit is >= PyLong_BASE: the max value for q is PyLong_BASE+1, and
2823 that won't overflow a digit. */
2841 /* normalize: shift w1 left so that its top digit is >= PyLong_BASE/2.
2869 single-digit quotient q, remainder in vk[0:size_w]. */
2879 /* estimate quotient digit q; may overestimate by 1 (rare) */
2884 * r = (digit)(vv - (twodigits)wm1 * q);
2890 q = (digit)(vv / wm1);
2891 r = (digit)(vv % wm1);
2908 vk[i] = (digit)z & PyLong_MASK;
2925 /* store quotient digit */
2958 digit rem;
2959 digit x_digits[2 + (DBL_MANT_DIG + 1) / PyLong_SHIFT] = {0,};
2961 /* Correction term for round-half-to-even rounding. For a digit x,
3080 /* Fast path; single digit long (31 bits) will cast safely
3197 digit carry = 0;
3232 digit borrow = 0;
3243 /* Find highest digit where a and b differ: */
3291 /* x_add received at least one multiple-digit int,
3292 and thus z must be a multiple-digit int.
3369 memset(z->ob_digit, 0, Py_SIZE(z) * sizeof(digit));
3377 digit *paend = a->ob_digit + size_a;
3381 digit *pz = z->ob_digit + (i << 1);
3382 digit *pa = a->ob_digit + i + 1;
3390 *pz++ = (digit)(carry & PyLong_MASK);
3400 *pz++ = (digit)(carry & PyLong_MASK);
3411 *pz = (digit)(carry & PyLong_MASK);
3417 * more than 2*B - 2 to a stored digit no more than 1.
3423 pz[1] = (digit)carry;
3432 digit *pz = z->ob_digit + i;
3433 digit *pb = b->ob_digit;
3434 digit *pbend = b->ob_digit + size_b;
3443 *pz++ = (digit)(carry & PyLong_MASK);
3448 *pz += (digit)(carry & PyLong_MASK);
3482 memcpy(lo->ob_digit, n->ob_digit, size_lo * sizeof(digit));
3483 memcpy(hi->ob_digit, n->ob_digit + size_lo, size_hi * sizeof(digit));
3569 * underflow (borrow out of the high digit), but we don't care:
3572 * borrows and carries out of the high digit can be ignored.
3583 memset(ret->ob_digit, 0xDF, Py_SIZE(ret) * sizeof(digit));
3591 Py_SIZE(t1) * sizeof(digit));
3597 i * sizeof(digit));
3606 memcpy(ret->ob_digit, t2->ob_digit, Py_SIZE(t2) * sizeof(digit));
3611 memset(ret->ob_digit + Py_SIZE(t2), 0, i * sizeof(digit));
3677 of shift. This leaves asize+bsize-shift allocated digit positions for t3
3679 asize + c(bsize/2) available digit positions.
3692 and we have asize + c(bsize/2) available digit positions. We need to show
3698 digit is enough to hold 2 bits. This is so since PyLong_SHIFT=15 >= 2. If
3733 memset(ret->ob_digit, 0, Py_SIZE(ret) * sizeof(digit));
3747 nbtouse * sizeof(digit));
3776 /* fast path for single-digit multiplication */
3799 /* Fast modulo division for single-digit longs. */
3822 /* Fast floor division for single-digit longs. */
3873 /* Fast path for single-digit longs */
3941 /* Fast path for single-digit longs */
3987 digit mask, low;
4059 To round, we just modify the bottom digit of x in-place; this can
4060 end up giving a digit with value > PyLONG_MASK, but that's not a
4141 digit rem;
4162 digit rem;
4183 digit rem = inplace_divrem1(x->ob_digit, x->ob_digit, x_size,
4208 /* Round by directly modifying the low digit of x. */
4209 mask = (digit)1 << (extra_bits - 1);
4522 digit bi = i ? b->ob_digit[i-1] : 0;
4523 digit bit;
4571 bit = (digit)1 << (PyLong_SHIFT-1);
4617 const digit bi = b->ob_digit[i];
4703 divmod_shift(PyObject *shiftby, Py_ssize_t *wordshift, digit *remshift)
4723 if (*wordshift >= 0 && *wordshift < PY_SSIZE_T_MAX / (Py_ssize_t)sizeof(digit)) {
4729 *wordshift = PY_SSIZE_T_MAX / sizeof(digit);
4739 long_rshift1(PyLongObject *a, Py_ssize_t wordshift, digit remshift)
4753 digit shift;
4804 digit sticky = 0;
4808 accum += (PyLong_MASK >> hishift) + (digit)(sticky != 0);
4814 z->ob_digit[i] = (digit)(accum & PyLong_MASK);
4818 z->ob_digit[newsize - 1] = (digit)accum;
4828 digit remshift;
4849 digit remshift;
4861 long_lshift1(PyLongObject *a, Py_ssize_t wordshift, digit remshift)
4890 z->ob_digit[i] = (digit)(accum & PyLong_MASK);
4894 z->ob_digit[newsize-1] = (digit)accum;
4905 digit remshift;
4926 digit remshift;
4937 /* Compute two's complement of digit vector a[0:m], writing result to
4938 z[0:m]. The digit vector a need not be normalized, but should not
4939 be entirely zero. a and z may point to the same digit vector. */
4942 v_complement(digit *z, digit *a, Py_ssize_t m)
4945 digit carry = 1;
5030 /* We allow an extra digit if z is negative, to make sure that
5063 (size_z-i)*sizeof(digit));
5131 digit *a_digit, *b_digit, *c_digit, *d_digit, *a_end, *b_end;
5264 *c_digit++ = (digit)(c_carry & PyLong_MASK);
5265 *d_digit++ = (digit)(d_carry & PyLong_MASK);
5272 *c_digit++ = (digit)(c_carry & PyLong_MASK);
5273 *d_digit++ = (digit)(d_carry & PyLong_MASK);
5418 /* Fast operations for single digit integers (including zero)
5419 * assume that there is always at least one digit present. */
5671 one digit, even though the integer zero has a Py_SIZE of 0 */
5672 + Py_MAX(Py_ABS(Py_SIZE(self)), 1)*sizeof(digit);
5694 digit msd;
5741 popcount_digit(digit d)
5743 // digit can be larger than uint32_t, but only PyLong_SHIFT bits
5745 static_assert(PyLong_SHIFT <= 32, "digit is larger than uint32_t");
5773 /* Each digit has up to PyLong_SHIFT ones, so the accumulated bit count
6062 sizeof(digit), /* tp_itemsize */
6111 {"bits_per_digit", "size of a digit in bits"},
6112 {"sizeof_digit", "size in bytes of the C type used to represent a digit"},
6136 PyLong_FromLong(sizeof(digit)));