// ToUnit converts a monetary amount counted in bitcoin base units to a
// floating point value representing an amount of bitcoin.
555499
func (a Amount) ToUnit(u AmountUnit) float64 {
	return float64(a) / math.Pow10(int(u+8))
}
1308698
func CountBitsByteAlt(x byte) int {
	x = (x & 0x55) + ((x >> 1) & 0x55)
	x = (x & 0x33) + ((x >> 2) & 0x33)
	return int((x & 0x0f) + ((x >> 4) & 0x0f))
}
402765
func ConvertUnitsString(val string, from Unit, to Unit) (float64, error) {
	floatValue, err := strconv.ParseFloat(val, 64)
	if err != nil {
		return 0, err
	}
	return ConvertUnits(floatValue, from, to), nil
}
371659
func isMemoryUnit(unit string) bool {
	switch strings.TrimSuffix(strings.ToLower(unit), "s") {
	case "byte", "b", "kilobyte", "kb", "megabyte", "mb", "gigabyte", "gb":
		return true
	}
	return false
}
277061
func (s *GetMetricStatisticsInput) SetUnit(v string) *GetMetricStatisticsInput {
	s.Unit = &v
	return s
}
698237
func (s *MetricDatum) SetUnit(v string) *MetricDatum {
	s.Unit = &v
	return s
}
1368740
func (s *CustomizedScalingMetricSpecification) SetUnit(v string) *CustomizedScalingMetricSpecification {
	s.Unit = &v
	return s
}
1232813
func FormatBytesUnit(s, u uint64) string {
	var rounded float64
	if s < 10 {
		rounded = float64(s)
	} else {
		rounded = math.Floor(float64(s)/float64(u)*10+.5) / 10
	}

	format := "%.0f"
	if rounded < 10 && u > 1 {
		format = "%.1f"
	}

	return fmt.Sprintf(format, rounded)
}
1082347
func DesignUnitsToPdf(val int, unitsPerEm uint) int {
	return core.Round(float64(float64(val) * 1000.00 / float64(unitsPerEm)))
}
1043903
func (s *DateRange) SetUnit(v string) *DateRange {
	s.Unit = &v
	return s
}
1249015
func (u AmountUnit) String() string {
	switch u {
	case AmountMegaBTC:
		return "MBTC"
	case AmountKiloBTC:
		return "kBTC"
	case AmountBTC:
		return "BTC"
	case AmountMilliBTC:
		return "mBTC"
	case AmountMicroBTC:
		return "μBTC"
	case AmountSatoshi:
		return "Satoshi"
	default:
		return "1e" + strconv.FormatInt(int64(u), 10) + " BTC"
	}
}
1279883
func NewUnit(m map[string]int64) (*Unit, error) {
	var found bool
	for _, mult := range m {
		if mult == 1 {
			found = true
			break
		}
	}
	if !found {
		return nil, fmt.Errorf("could not find unit that maps to multiplier 1 for %v", m)
	}
	return &Unit{m}, nil
}
166557
func ToUnixMilli(t time.Time) int64 {
	return t.UnixNano() / (int64(time.Millisecond) / int64(time.Nanosecond))
}
381407
func ToInt(value interface{}) (int64, error) {
	v := reflect.ValueOf(value)
	switch v.Kind() {
	case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
		return v.Int(), nil
	}
	return 0, fmt.Errorf("cannot convert %v to int64", v.Kind())
}
58079
func (s *Bitset) BitCount() int {
	var n int
	s.unsetTop()
	for i, l := 0, len(s.set); i < l; i++ {
		n += BitCount(s.set[i])
	}

	return n
}
223976
func (s *DescribeAlarmsForMetricInput) SetUnit(v string) *DescribeAlarmsForMetricInput {
	s.Unit = &v
	return s
}
39490
func (s *CustomizedMetricSpecification) SetUnit(v string) *CustomizedMetricSpecification {
	s.Unit = &v
	return s
}