Lines Matching defs:shift

304     /* Do shift in two steps to avoid possible undefined behavior. */
1131 /* Do shift in two steps to avoid possible undefined behavior. */
2540 /* Calculate the shift only if we couldn't get
2841 /* normalize: shift w1 left so that its top digit is >= PyLong_BASE/2.
2842 shift v1 left by the same amount. Results go into w and v. */
3022 bit of x to be 'sticky' for this shift: if any of the bits
3458 viewing the shift as being by digits. The sign bit is ignored, and
3507 Py_ssize_t shift; /* the number of digits we split off */
3550 shift = bsize >> 1;
3551 if (kmul_split(a, shift, &ah, &al) < 0) goto fail;
3560 else if (kmul_split(b, shift, &bh, &bl) < 0) goto fail;
3565 * 2. Compute ah*bh, and copy into result at 2*shift.
3568 * 4. Subtract al*bl from the result, starting at shift. This may
3573 * 5. Subtract ah*bh from the result, starting at shift.
3575 * at shift.
3589 assert(2*shift + Py_SIZE(t1) <= Py_SIZE(ret));
3590 memcpy(ret->ob_digit + 2*shift, t1->ob_digit,
3594 i = Py_SIZE(ret) - 2*shift - Py_SIZE(t1);
3596 memset(ret->ob_digit + 2*shift + Py_SIZE(t1), 0,
3605 assert(Py_SIZE(t2) <= 2*shift); /* no overlap with high digits */
3609 i = 2*shift - Py_SIZE(t2); /* number of uninitialized digits */
3616 i = Py_SIZE(ret) - shift; /* # digits after shift */
3617 (void)v_isub(ret->ob_digit + shift, i, t2->ob_digit, Py_SIZE(t2));
3620 (void)v_isub(ret->ob_digit + shift, i, t1->ob_digit, Py_SIZE(t1));
3650 (void)v_iadd(ret->ob_digit + shift, i, t3->ob_digit, Py_SIZE(t3));
3671 2. shift = f(bsize/2)
3677 of shift. This leaves asize+bsize-shift allocated digit positions for t3
3986 Py_ssize_t a_size, b_size, shift, extra_bits, diff, x_size, x_bits;
3999 1. choose a suitable integer 'shift'
4000 2. use integer arithmetic to compute x = floor(2**-shift*a/b)
4003 5. return ldexp(dx, shift).
4023 1. The integer 'shift' is chosen so that x has the right number of
4027 straightforward formula for shift is:
4029 shift = a_bits - b_bits - DBL_MANT_DIG - 2
4036 shift = MAX(a_bits - b_bits, DBL_MIN_EXP) - DBL_MANT_DIG - 2
4038 2. The quantity x is computed by first shifting a (left -shift bits
4039 if shift <= 0, right shift bits if shift > 0) and then dividing by
4040 b. For both the shift and the division, we keep track of whether
4044 With the choice of shift above, together with our assumption that
4048 3. Now x * 2**shift <= a/b < (x+1) * 2**shift. We want to replace
4051 round(x/2**extra_bits) * 2**(extra_bits+shift).
4054 2**DBL_MANT_DIG and extra_bits + shift >= DBL_MIN_EXP -
4057 extra_bits >= MAX(x_bits, DBL_MIN_EXP - shift) - DBL_MANT_DIG
4063 With the original choices for shift above, extra_bits will always
4074 5. Use ldexp(x, shift) to compute x*2**shift, the final result.
4133 /* Choose value for shift; see comments for step 1 above. */
4134 shift = Py_MAX(diff, DBL_MIN_EXP) - DBL_MANT_DIG - 2;
4138 /* x = abs(a * 2**-shift) */
4139 if (shift <= 0) {
4140 Py_ssize_t i, shift_digits = -shift / PyLong_SHIFT;
4142 /* x = a << -shift */
4157 a_size, -shift % PyLong_SHIFT);
4161 Py_ssize_t shift_digits = shift / PyLong_SHIFT;
4163 /* x = a >> shift */
4169 a_size - shift_digits, shift % PyLong_SHIFT);
4205 extra_bits = Py_MAX(x_bits, DBL_MIN_EXP - shift) - DBL_MANT_DIG;
4222 if (shift + x_bits >= DBL_MAX_EXP &&
4223 (shift + x_bits > DBL_MAX_EXP || dx == ldexp(1.0, (int)x_bits)))
4225 result = ldexp(dx, (int)shift);
4727 /* Clip the value. With such large wordshift the right shift
4728 returns 0 and the left shift raises an error in _PyLong_New(). */
4753 digit shift;
4755 shift = wordshift == 0 ? remshift : PyLong_SHIFT;
4756 x = m < 0 ? ~(~m >> shift) : m >> shift;
4769 /* Can only happen if the original shift was 0. */
4792 For a positive integer a and nonnegative shift, we have:
4794 (-a) >> shift == -((a + 2**shift - 1) >> shift).
4796 In the addition `a + (2**shift - 1)`, the low `wordshift` digits of
4797 `2**shift - 1` all have value `PyLong_MASK`, so we get a carry out
4800 of `2**shift - 1` has value `PyLong_MASK >> hishift`.
4833 PyErr_SetString(PyExc_ValueError, "negative shift count");
4869 // bypass undefined shift operator behavior
4910 PyErr_SetString(PyExc_ValueError, "negative shift count");