signed integer to balanced ternary string
483673
function n2bts(n_) {
  var neg = n_ < 0;
  var n = Math.abs(n_);
  var s = '';
  do {
    var digit = n % 3;

    // balance the ternary http://stackoverflow.com/questions/26456597/how-to-convert-from-unbalanced-to-balanced-ternary
    if (digit === 2) {
      digit = -1;
      ++n;
    }

    //console.log('digit',digit,n,n_,s);

    // if number has negative sign, flip all digits
    if (neg) {
      digit = -digit;
    }

    s = N_TO_BT_DIGIT[digit] + s;
    n = ~~(n / 3);    // truncate, not floor! negatives

  } while(n);
  //console.log('n2bts',n_,s);
  return s;
}
851356
private static int integerPart(String dirtyString) {
    int start = 0;

    while (start < dirtyString.length() && !Character.isDigit(dirtyString.charAt(start))) {
      ++start;
    }

    int end = start;
    while (end < dirtyString.length() && Character.isDigit(dirtyString.charAt(end))) {
      ++end;
    }

    if (start == end) {
      return 0;
    }

    return Integer.parseInt(dirtyString.substring(start, end));
  }
743672
def str(self, value, tolerant=False, limit=1000, seen=frozenset()):
        """"""
        if value is None:
            if tolerant:
                return ""

            raise ValueError("value is None")

        if isinstance(value, (bool, numbers.Number, basestring)):
            return str(value)

        if not isinstance(value, collections.Iterable):
            if not tolerant:
                raise ValueError("unknown value type")

            try:
                name = value.name
            except AttributeError:
                try:
                    name = value.__name__
                except AttributeError:
                    try:
                        name = value.__class__.__name__
                    except AttributeError:
                        return "<?>"

            return "<%s>" % (name,)

        is_mapping = isinstance(value, collections.Mapping)

        if not seen:
            wrap = "%s"
        elif is_mapping:
            wrap = "{%s}"
        else:
            wrap = "[%s]"

        id_ = id(value)
        if id_ in seen:
            if tolerant:
                return wrap % ("...",)
            raise ValueError("recursive representation")
        seen = seen.union((id_,))

        if is_mapping:
            items = [(self.str(n, tolerant=tolerant, limit=limit, seen=seen),
                      self.str(v, tolerant=tolerant, limit=limit, seen=seen))
                     for n, v in value.items()]
            items.sort()
            items = ("%s=%s" for n, v in items)
        else:
            it = iter(value)
            items = [self.str(item, tolerant=tolerant, limit=limit, seen=seen)
                     for item in itertools.islice(
                         it,
                         len(value)
                         if isinstance(value, collections.Sized)
                         else limit)]
            items.sort()
            try:
                next(it)
            except StopIteration:
                pass
            else:
                if not tolerant:
                    raise ValueError("iterable too long")
                items.append("...")

        return wrap % (", ".join(items),)
278570
static String toUnsignedString(long l) {
    BigInteger b = BigInteger.valueOf(l);
    if (b.signum() < 0) {
      b = b.add(TWO_64);
    }
    return b.toString();
  }
1216858
def _set_from_whole_string(rop, s, base, rnd):
    
    s = s.strip()
    ternary, endindex = mpfr.mpfr_strtofr(rop, s, base, rnd)
    if len(s) != endindex:
        raise ValueError("not a valid numeric string")
    return ternary
9707
function int2Str36(num) {
    let baseIdx = d36.length;
    let result = [];
    let empty = null;
    if (num === 0) return '0';
    for (let i = 0; i < baseIdx; i++) {
        let d = d36[i];
        let c = 0;
        if (d <= num) {
            c = Math.trunc(num/d);
            num -= d * c;
            c = encodeCharCode2Int36(c);
            empty = encodeCharCode2Int36(0);
        } else {
            c = empty;
        }
        if (c) result.push(c);
    }
    return String.fromCharCode.apply(null, result);
}
549578
def _validate_int(name, value, limits=(), strip='%'):
    '''
    
    '''
    comment = ''
    # Must be integral
    try:
        if isinstance(value, string_types):
            value = value.strip(' ' + strip)
        value = int(value)
    except (TypeError, ValueError):
        comment += '{0} must be an integer '.format(name)
    # Must be in range
    else:
        if len(limits) == 2:
            if value < limits[0] or value > limits[1]:
                comment += '{0} must be in the range [{1[0]}, {1[1]}] '.format(name, limits)
    return value, comment
537000
def signed_to_float(hex: str) -> float:
    """"""
    if int(hex, 16) & 0x8000:
        return -(int(hex, 16) & 0x7FFF) / 10
    else:
        return int(hex, 16) / 10
435962
def is_symbol(string):
    
    return (
        is_int(string) or is_float(string) or
        is_constant(string) or is_unary(string) or
        is_binary(string) or
        (string == '(') or (string == ')')
    )
1310546
function sign(value, pow) {
  const msb = 1 << pow;
  if ((value & msb) === 0) {
    return value;
  }
  let neg = -1 * (value & msb);
  neg += (value & (msb - 1));
  return neg;
}
1336075
static Integer emptyToNullInteger(final String s) {
        return "".equals(s) ? null : Integer.parseInt(s);
    }
333922
def _SignedVarintEncoder():
  """"""

  local_chr = chr
  def EncodeSignedVarint(write, value):
    if value < 0:
      value += (1 << 64)
    bits = value & 0x7f
    value >>= 7
    while value:
      write(0x80|bits)
      bits = value & 0x7f
      value >>= 7
    return write(bits)

  return EncodeSignedVarint
1101220
def positive_float(string):
    """"""
    error_msg = 'Positive float required, {string} given.'.format(string=string)
    try:
        value = float(string)
    except ValueError:
        raise ArgumentTypeError(error_msg)
    if value < 0:
        raise ArgumentTypeError(error_msg)
    return value
540547
def paddedInt(i):
    '''
    
    '''
    i_str = str(i)
    pad = PAD_LEN - len(i_str)
    return (pad * "0") + i_str
883094
function (mixed, base) {
            var type = typeof mixed;

            base = base || 10;

            if (type === "boolean") {
                return +mixed;

            } else if (type === "string") {
                mixed   = mixed.replace(/\s/g, "");
                var tmp = parseInt(mixed, base);
                return (isNaN(tmp) || !isFinite(tmp)) ? 0 : tmp;

            } else if (type === "number" && isFinite(mixed)) {
                /* jshint -W016 */
                return mixed | 0;
                /* jshint +W016 */

            } else {
                return 0;
            }
        }
145517
def validate_positive_integer(option, value):
    
    val = validate_integer(option, value)
    if val <= 0:
        raise ValueError("The value of %s must be "
                         "a positive integer" % (option,))
    return val
1310048
def from_int(cls, integer):
        
        bin_string = bin(integer)

        return cls(
            text=len(bin_string) >= 1 and bin_string[-1] == "1",
            comment=len(bin_string) >= 2 and bin_string[-2] == "1",
            user=len(bin_string) >= 3 and bin_string[-3] == "1",
            restricted=len(bin_string) >= 4 and bin_string[-4] == "1"
        )