Format BF10 to floating point or scientific notation.
778891
def _format_bf(bf, precision=3, trim='0'):
    
    if bf >= 1e4 or bf <= 1e-4:
        out = np.format_float_scientific(bf, precision=precision, trim=trim)
    else:
        out = np.format_float_positional(bf, precision=precision, trim=trim)
    return out
165206
def encode(self):
        """"""
        return '{:.6f} {:.6f} {:.6f} {:.6f} {:.6f} {:.6f}'.format(
            self.a, self.b, self.c, self.d, self.e, self.f
        ).encode()
148608
def _pprint(params):
    """"""
    params_list = list()
    line_sep = ','
    for i, (k, v) in enumerate(sorted(params.iteritems())):
        if type(v) is float:
            # use str for representing floating point numbers
            # this way we get consistent representation across
            # architectures and versions.
            this_repr = '%s=%.10f' % (k, v)
        else:
            # use repr of the rest
            this_repr = '%s=%r' % (k, v)
        params_list.append(this_repr)

    lines = ','.join(params_list)
    return lines
551790
def _si(number):
    """"""
    prefixes = ['', 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y']
    while number > 1024:
        number /= 1024.0
        prefixes.pop(0)
    return '%0.2f%s' % (number, prefixes.pop(0))
102676
private String formatCoef(double coef) {
		double tol = 1e-6; // rounding tolerance

		// zero case
		if( Math.abs(coef) < tol) {
			return "0";
		}

		// integer case
		long num = Math.round(coef);
		if( Math.abs(num - coef) < tol) {
			return Long.toString(num);
		}

		// Other small cases
		for(int denom = 2; denom < 12; denom++ ) {
			num = Math.round(coef*denom);
			if( num - coef*denom < tol ) {
				return String.format("%d/%d",num, denom);
			}
		}

		// Give up and use floating point;
		return String.format("%.3f", coef);
	}
1063902
def convert_bytes(bytes_, K=1 << 10, M=1 << 20, G=1 << 30, T=1 << 40):
    """"""
    fn = float(bytes_)
    if bytes_ >= T:
        return '%.1fT' % (fn / T)
    elif bytes_ >= G:
        return '%.1fG' % (fn / G)
    elif bytes_ >= M:
        return '%.1fM' % (fn / M)
    elif bytes_ >= K:
        return '%.1fK' % (fn / K)
    else:
        return '%d' % bytes_
929491
def _f16_to_32bit(ins):
    
    ins.quad = [x for x in ins.quad]
    for i in range(2, len(ins.quad)):
        if is_float(ins.quad[i]):
            de, hl = f16(ins.quad[i])
            ins.quad[i] = str((de << 16) | hl)

    ins.quad = tuple(ins.quad)
    return ins
251739
def padto8(data):
    """"""
    length = len(data)
    return data + b'\xdb' * (roundto8(length) - length)
1203479
def format_(num, n=8):
    
    if num is None:
        return 'None'
    if util_type.is_float(num):
        ret = ('%.' + str(n) + 'E') % num
        exp_pos  = ret.find('E')
        exp_part = ret[(exp_pos + 1):]
        exp_part = exp_part.replace('+', '')
        if exp_part.find('-') == 0:
            exp_part = '-' + exp_part[1:].strip('0')
        exp_part = exp_part.strip('0')
        if len(exp_part) > 0:
            exp_part = 'E' + exp_part
        flt_part = ret[:exp_pos].strip('0').strip('.')
        ret = flt_part + exp_part
        return ret
    return '%d' % num
1285808
def format_decimal(decimal):
    
    # strip trailing fractional zeros
    normalized = decimal.normalize()
    sign, digits, exponent = normalized.as_tuple()
    if exponent >= 1:
        normalized = normalized.quantize(1)

    return str(normalized)
274132
def encode(precision, with_z):
    """"""
    logger = logging.getLogger('geobuf')
    stdin = click.get_text_stream('stdin')
    sink = click.get_binary_stream('stdout')
    try:
        data = json.load(stdin)
        pbf = geobuf.encode(
            data,
            precision if precision >= 0 else 6,
            3 if with_z else 2)
        sink.write(pbf)
        sys.exit(0)
    except Exception:
        logger.exception("Failed. Exception caught")
        sys.exit(1)
670582
def _format_number_si(num, n_signif_figures):
    """"""
    if math.isnan(num) or math.isinf(num):
        return str(num)
    leading, exp = '{:E}'.format(num).split('E')
    leading = round(float(leading), n_signif_figures - 1)
    exp = exp[:1] + exp[2:] if exp[1] == '0' else exp
    formatted = '{}e{}'.format(leading, exp.lstrip('+'))
    return formatted
1083063
function readNumber(bf, numfmt) {
  var value = new Uint8Array(bf);
  if (numfmt === NUMFMT_UINT32) {
    // uint32
    return uint32BEtoNumber(value);
  } else if (numfmt === NUMFMT_UINT64) {
    // uint64
    return uint64BEtoNumber(value);
  } else if (numfmt === NUMFMT_UINT16) {
    // uint16
    return uint16BEtoNumber(value);
  } else if (numfmt === NUMFMT_UINT8) {
    // uint8
    return uint8BEtoNumber(value);
  }
  return 0;

  // return struct.unpack(this._number_format, bf)[0];
}
472471
def _pwm_to_str(self, precision=4):
        
        if not self.pwm:
            return ""
        
        fmt = "{{:.{:d}f}}".format(precision)
        return "\n".join(
                ["\t".join([fmt.format(p) for p in row])
                for row in self.pwm]
                )
103450
def base10toN(num, n):
    """"""
    num_rep = {10:'a',
         11:'b',
         12:'c',
         13:'d',
         14:'e',
         15:'f',
         16:'g',
         17:'h',
         18:'i',
         19:'j',
         20:'k',
         21:'l',
         22:'m',
         23:'n',
         24:'o',
         25:'p',
         26:'q',
         27:'r',
         28:'s',
         29:'t',
         30:'u',
         31:'v',
         32:'w',
         33:'x',
         34:'y',
         35:'z'}
    new_num_string = ''
    new_num_arr = array(())
    current = num
    while current != 0:
        remainder = current % n
        if 36 > remainder > 9:
            remainder_string = num_rep[remainder]
        elif remainder >= 36:
            remainder_string = '(' + str(remainder) + ')'
        else:
            remainder_string = str(remainder)
        new_num_string = remainder_string + new_num_string
        new_num_arr = r_[remainder, new_num_arr]
        current = current / n
    print(new_num_arr)
    return new_num_string
714936
def convertbase(number, base=10):
    

    integer = number
    if not integer:
        return '0'
    sign = 1 if integer > 0 else -1
    alphanum = string.digits + string.ascii_lowercase
    nums = alphanum[:base]
    res = ''
    integer *= sign
    while integer:
        integer, mod = divmod(integer, base)
        res += nums[mod]
    return ('' if sign == 1 else '-') + res[::-1]
803814
def write_numeric(fmt, value, buff, byteorder='big'):
    """"""
    try:
        buff.write(fmt[byteorder].pack(value))
    except KeyError as exc:
        raise ValueError('Invalid byte order') from exc