General power-of-2 base conversion.
498
def convertbits(data, frombits, tobits, pad=True):
    """"""
    acc = 0
    bits = 0
    ret = []
    maxv = (1 << tobits) - 1
    max_acc = (1 << (frombits + tobits - 1)) - 1
    for value in data:
        if value < 0 or (value >> frombits):
            return None
        acc = ((acc << frombits) | value) & max_acc
        bits += frombits
        while bits >= tobits:
            bits -= tobits
            ret.append((acc >> bits) & maxv)
    if pad:
        if bits:
            ret.append((acc << (tobits - bits)) & maxv)
    elif bits >= frombits or ((acc << (tobits - bits)) & maxv):
        return None
    return ret
1272200
public function baseConvert(array $source, int $sourceBase, int $targetBase): array
    {
        $result = [];
        while ($count = count($source)) {
            $quotient = [];
            $remainder = "0";
            $sourceBase = (string) $sourceBase;
            $targetBase = (string) $targetBase;
            for ($i = 0; $i !== $count; $i++) {
                $accumulator = bcadd((string) $source[$i], bcmul($remainder, $sourceBase));
                $digit = bcdiv($accumulator, $targetBase, 0);
                $remainder = bcmod($accumulator, $targetBase);
                if (count($quotient) || $digit) {
                    array_push($quotient, $digit);
                };
            }
            array_unshift($result, $remainder);
            $source = $quotient;
        }

        return $result;
    }
830531
def next_power_of_2(x):
    

    power_of_2 = 1 if x == 0 else 2 ** np.ceil(np.log2(x))
    return power_of_2
621227
def modular_exponential(base, exponent, mod):
    """"""
    if exponent < 0:
        raise ValueError("Exponent must be positive.")
    base %= mod
    result = 1

    while exponent > 0:
        # If the last bit is 1, add 2^k.
        if exponent & 1:
            result = (result * base) % mod
        exponent = exponent >> 1
        # Utilize modular multiplication properties to combine the computed mod C values.
        base = (base * base) % mod

    return result
103874
def _scalar_power(self, f, p, out):
        """"""
        # Avoid infinite recursions by making a copy of the function
        f_copy = f.copy()

        def pow_posint(x, n):
            """Power function for positive integer ``n``, out-of-place."""
            if isinstance(x, np.ndarray):
                y = x.copy()
                return ipow_posint(y, n)
            else:
                return x ** n

        def ipow_posint(x, n):
            """Power function for positive integer ``n``, in-place."""
            if n == 1:
                return x
            elif n % 2 == 0:
                x *= x
                return ipow_posint(x, n // 2)
            else:
                tmp = x.copy()
                x *= x
                ipow_posint(x, n // 2)
                x *= tmp
                return x

        def power_oop(x, **kwargs):
            """Power out-of-place evaluation function."""
            if p == 0:
                return self.one()
            elif p == int(p) and p >= 1:
                return np.asarray(pow_posint(f_copy(x, **kwargs), int(p)),
                                  dtype=self.scalar_out_dtype)
            else:
                result = np.power(f_copy(x, **kwargs), p)
                return result.astype(self.scalar_out_dtype)

        out._call_out_of_place = power_oop
        decorator = preload_first_arg(out, 'in-place')
        out._call_in_place = decorator(_default_in_place)
        out._call_has_out = out._call_out_optional = False
        return out
1357727
def bhp2pascal(bhp, cfm, fan_tot_eff):
    """"""
    inh2o = bhp * 6356.0 * fan_tot_eff / cfm
    pascal = inh2o2pascal(inh2o)        
    m3s = cfm2m3s(cfm)
    return pascal, m3s
253398
def rs_generator_poly(nsym, fcr=0, generator=2):
    ''''''
    g = bytearray([1])
    for i in xrange(nsym):
        g = gf_poly_mul(g, [1, gf_pow(generator, i+fcr)])
    return g
655065
function b2a(b) {
	var out = new Array(b.length);
	for(var i = 0; i < out.length; i++) out[i] = (b[i] < 0 ? b[i] + 256 : b[i]);
	return out;
}
422196
private int ssMedian5(int Td, int PA, int v1, int v2, int v3, int v4, int v5) {
        int t;
        if (T[start + Td + SA[PA + SA[v2]]] > T[start + Td + SA[PA + SA[v3]]]) {
            t = v2;
            v2 = v3;
            v3 = t;

        }
        if (T[start + Td + SA[PA + SA[v4]]] > T[start + Td + SA[PA + SA[v5]]]) {
            t = v4;
            v4 = v5;
            v5 = t;
        }
        if (T[start + Td + SA[PA + SA[v2]]] > T[start + Td + SA[PA + SA[v4]]]) {
            t = v2;
            v2 = v4;
            v4 = t;
            t = v3;
            v3 = v5;
            v5 = t;
        }
        if (T[start + Td + SA[PA + SA[v1]]] > T[start + Td + SA[PA + SA[v3]]]) {
            t = v1;
            v1 = v3;
            v3 = t;
        }
        if (T[start + Td + SA[PA + SA[v1]]] > T[start + Td + SA[PA + SA[v4]]]) {
            t = v1;
            v1 = v4;
            v4 = t;
            t = v3;
            v3 = v5;
            v5 = t;
        }
        if (T[start + Td + SA[PA + SA[v3]]] > T[start + Td + SA[PA + SA[v4]]]) {
            return v4;
        }
        return v3;
    }
554204
def power(attrs, inputs, proto_obj):
    """"""
    new_attrs = translation_utils._fix_attribute_names(attrs, {'exponent':'exp'})
    if 'broadcast' in attrs:
        new_attrs = translation_utils._remove_attributes(new_attrs, ['broadcast'])
        if attrs['broadcast'] == 1:
            return 'broadcast_power', new_attrs, inputs
        else:
            mxnet_op = symbol.pow(inputs[0], inputs[1])
            return mxnet_op, new_attrs, inputs
    mxnet_op = symbol.broadcast_power(inputs[0], inputs[1])
    return mxnet_op, new_attrs, inputs
1342044
def power(n, m)
      result = 1
      v = n
      while m > 0
        result = mod result * v if m.odd?
        v = square v
        m >>= 1
      end
      result
    end
931314
def bitwise_or(self, t):
        
        """
        This implementation combines the approaches used by 'WYSINWYX: what you see is not what you execute'
        paper and 'Signedness-Agnostic Program Analysis: Precise Integer Bounds for Low-Level Code'. The
        first paper provides an sound way to approximate the stride, whereas the second provides a way
        to calculate the or operation using wrapping intervals.
        Note that, even though according Warren's work 'Hacker's delight', one should follow different
        approaches to calculate the minimun/maximum values of an or operations according on the type
        of the operands (signed/unsigned). On the other other hand, by splitting the wrapping-intervals
        at the south pole, we can safely and soundly only use the Warren's functions for unsigned
        integers.
        """
        s = self
        result_interval = list()

        for u in s._ssplit():
            for v in t._ssplit():
                w = u.bits
                # u |w v
                if u.is_integer:
                    s_t = StridedInterval._ntz(v.stride)
                elif v.is_integer:
                    s_t = StridedInterval._ntz(u.stride)
                else:
                    s_t = min(StridedInterval._ntz(u.stride), StridedInterval._ntz(v.stride))

                if u.is_integer and u.lower_bound == 0:
                    new_stride = v.stride
                elif v.is_integer and v.lower_bound == 0:
                    new_stride = u.stride
                else:
                    new_stride = 2 ** s_t
                mask = (1 << s_t) - 1
                r = (u.lower_bound & mask) | (v.lower_bound & mask)
                m = (2 ** w) - 1
                low_bound = WarrenMethods.min_or(u.lower_bound & (~mask & m), u.upper_bound & (~mask & m), v.lower_bound & (~mask & m), v.upper_bound & (~mask & m), w)
                upper_bound = WarrenMethods.max_or(u.lower_bound & (~mask & m), u.upper_bound & (~mask & m), v.lower_bound & (~mask & m), v.upper_bound & (~mask & m), w)
                if low_bound == upper_bound:
                    new_stride = 0

                new_interval = StridedInterval(lower_bound=((low_bound & (~mask & m)) | r), upper_bound=((upper_bound & (~mask & m)) | r), bits=w, stride=new_stride)
                result_interval.append(new_interval)

        return StridedInterval.least_upper_bound(*result_interval).normalize()
455548
def _gh(self, x):
        
        Pgen = x[self._Pg.i1:self._Pg.iN + 1] # Active generation in p.u.
        Qgen = x[self._Qg.i1:self._Qg.iN + 1] # Reactive generation in p.u.

        for i, gen in enumerate(self._gn):
            gen.p = Pgen[i] * self._base_mva # active generation in MW
            gen.q = Qgen[i] * self._base_mva # reactive generation in MVAr

        # Rebuild the net complex bus power injection vector in p.u.
        Sbus = self.om.case.getSbus(self._bs)

        Vang = x[self._Va.i1:self._Va.iN + 1]
        Vmag = x[self._Vm.i1:self._Vm.iN + 1]
        V = Vmag * exp(1j * Vang)

        # Evaluate the power flow equations.
        mis = V * conj(self._Ybus * V) - Sbus

        # Equality constraints (power flow).
        g = r_[mis.real,  # active power mismatch for all buses
               mis.imag]  # reactive power mismatch for all buses

        # Inequality constraints (branch flow limits).
        # (line constraint is actually on square of limit)
        flow_max = array([(l.rate_a / self._base_mva)**2 for l in self._ln])
        # FIXME: There must be a more elegant method for this.
        for i, v in enumerate(flow_max):
            if v == 0.0:
                flow_max[i] = Inf

        if self.flow_lim == IFLOW:
            If = self._Yf * V
            It = self._Yt * V
            # Branch current limits.
            h = r_[(If * conj(If)) - flow_max,
                   (It * conj(It)) - flow_max]
        else:
            i_fbus = [e.from_bus._i for e in self._ln]
            i_tbus = [e.to_bus._i for e in self._ln]
            # Complex power injected at "from" bus (p.u.).
            Sf = V[i_fbus] * conj(self._Yf * V)
            # Complex power injected at "to" bus (p.u.).
            St = V[i_tbus] * conj(self._Yt * V)
            if self.flow_lim == PFLOW: # active power limit, P (Pan Wei)
                # Branch real power limits.
                h = r_[Sf.real()**2 - flow_max,
                       St.real()**2 - flow_max]
            elif self.flow_lim == SFLOW: # apparent power limit, |S|
                # Branch apparent power limits.
                h = r_[(Sf * conj(Sf)) - flow_max,
                       (St * conj(St)) - flow_max].real
            else:
                raise ValueError

        return h, g
1328740
private void voltConvertBinaryLiteralOperandsToBigint() {
        // Strange that CONCAT is an arithmetic operator.
        // You could imagine using it for VARBINARY, so
        // definitely don't convert its operands to BIGINT!
        assert(opType != OpTypes.CONCAT);

        for (int i = 0; i < nodes.length; ++i) {
            Expression e = nodes[i];
            ExpressionValue.voltMutateToBigintType(e, this, i);
        }
    }
632540
function x_to_y2 (t, y2, x) {
        sqr(t, x);
        mul_small(y2, x, 486662);
        add(t, t, y2);
        add(t, t, C1);
        mul(y2, t, x);
    }
791613
function modularScale(power, ratio, bases) {
  const scale = []
  let step = 0

  while (Math.abs(step) <= Math.abs(power)) {
    for (let i = 0; i < bases.length; i++) {
      scale.push(bases[i] * Math.pow(ratio, step))
    }

    step += 1

    if (power < 0) {
      step -= 2
    }
  }

  return Array.from(new Set(scale))[Math.abs(step) - 1] // eslint-disable-line no-undef
}
843673
function fft(re, im, inv) {
    var d, h, ik, m, tmp, wr, wi, xr, xi,
        n4 = _n >> 2;
    // bit reversal
    for(var l=0; l<_n; l++) {
      m = _bitrev[l];
      if(l < m) {
        tmp = re[l];
        re[l] = re[m];
        re[m] = tmp;
        tmp = im[l];
        im[l] = im[m];
        im[m] = tmp;
      }
    }
    // butterfly operation
    for(var k=1; k<_n; k<<=1) {
      h = 0;
      d = _n/(k << 1);
      for(var j=0; j<k; j++) {
        wr = _cstb[h + n4];
        wi = inv*_cstb[h];
        for(var i=j; i<_n; i+=(k<<1)) {
          ik = i + k;
          xr = wr*re[ik] + wi*im[ik];
          xi = wr*im[ik] - wi*re[ik];
          re[ik] = re[i] - xr;
          re[i] += xr;
          im[ik] = im[i] - xi;
          im[i] += xi;
        }
        h += d;
      }
    }
  }