// Mantissa returns the mantissa of x. If the mantissa cannot fit into a uint64
// or x is not finite, the bool will be false. This may be used to convert a
// decimal representing a monetary to its most basic unit (e.g., $123.45 to 12345
// cents.)
344751
func Mantissa(x *decimal.Big) (uint64, bool) {
	mp, _ := decimal.Raw(x)
	return *mp, x.IsFinite() && *mp != c.Inflated
}
53656
func ConvertUnits(val float64, from Unit, to Unit) float64 {
	value := Unit(val)
	// convert to I unit by multiplying with the current unit
	value *= from
	// convert to the target unit by dividing by it
	if to == I {
		return math.Round(float64(value))
	}
	value /= to
	return float64(value)
}
809167
func HexToECDSA(hexkey string) (*ecdsa.PrivateKey, error) {
	b, err := hex.DecodeString(hexkey)
	if err != nil {
		return nil, errors.New("invalid hex string")
	}
	return ToECDSA(b)
}
78166
func (c Client) Cos(x, y Expr) (float32, error) {
	req := cosQuery{A: x, B: y}
	body, err := c.fetch(req, "cos")
	if err != nil {
		return 0.0, err
	}

	var data cosResponse
	err = json.Unmarshal(body, &data)
	if err != nil {
		return 0.0, fmt.Errorf("error unmarshalling result: %v", err)
	}

	return data.Value, nil
}
654988
func Sincos(x float32) (sin, cos float32) {
	sin64, cos64 := math.Sincos(float64(x))
	sin = float32(sin64)
	cos = float32(cos64)
	return
}
274501
func (bot *ExchangeBot) Conversion(dcrVal float64) *Conversion {
	if bot == nil {
		return nil
	}
	xcState := bot.State()
	if xcState != nil {
		return &Conversion{
			Value: xcState.Price * dcrVal,
			Index: xcState.BtcIndex,
		}
	}
	return nil
}
385324
func (f *extFloat) floatBits(flt *floatInfo) (bits uint64, overflow bool) {
	f.Normalize()

	exp := f.exp + 63

	// Exponent too small.
	if exp < flt.bias+1 {
		n := flt.bias + 1 - exp
		f.mant >>= uint(n)
		exp += n
	}

	// Extract 1+flt.mantbits bits from the 64-bit mantissa.
	mant := f.mant >> (63 - flt.mantbits)
	if f.mant&(1<<(62-flt.mantbits)) != 0 {
		// Round up.
		mant += 1
	}

	// Rounding might have added a bit; shift down.
	if mant == 2<<flt.mantbits {
		mant >>= 1
		exp++
	}

	// Infinities.
	if exp-flt.bias >= 1<<flt.expbits-1 {
		// ±Inf
		mant = 0
		exp = 1<<flt.expbits - 1 + flt.bias
		overflow = true
	} else if mant&(1<<flt.mantbits) == 0 {
		// Denormalized?
		exp = flt.bias
	}
	// Assemble bits.
	bits = mant & (uint64(1)<<flt.mantbits - 1)
	bits |= uint64((exp-flt.bias)&(1<<flt.expbits-1)) << flt.mantbits
	if f.neg {
		bits |= 1 << (flt.mantbits + flt.expbits)
	}
	return
}
86967
func ParseAlias(val string) (string, string, error) {
	if val == "" {
		return "", "", errors.New("empty string specified for alias")
	}
	arr := strings.Split(val, ":")
	if len(arr) > 2 {
		return "", "", fmt.Errorf("bad format for alias: %s", val)
	}
	if len(arr) == 1 {
		return val, val, nil
	}
	return arr[0], arr[1], nil
}
990878
func fitsInOctal(n int, x int64) bool {
	octBits := uint(n-1) * 3
	return x >= 0 && (n >= 22 || x < 1<<octBits)
}
1284870
func (u *Ugen) Sqrsum(val Input) Input {
	return binOpSqrsum(u.Rate, u, val, u.NumOutputs)
}
1102563
func cryptotext(ctx context.Context, usv libsass.SassValue) (*libsass.SassValue, error) {

	c := 10
	b := make([]byte, c)
	_, err := rand.Read(b)
	if err != nil {
		return nil, err
	}
	res, err := libsass.Marshal(fmt.Sprintf("'%x'", b))
	return &res, err
}
846213
func bigFtoa(dst []byte, prec int, fmt byte, neg bool, mant uint64, exp int, flt *floatInfo) []byte {
	d := new(decimal)
	d.Assign(mant)
	d.Shift(exp - int(flt.mantbits))
	var digs decimalSlice
	shortest := prec < 0
	if shortest {
		roundShortest(d, mant, exp, flt)
		digs = decimalSlice{d: d.d[:], nd: d.nd, dp: d.dp}
		// Precision for shortest representation mode.
		switch fmt {
		case 'e', 'E':
			prec = digs.nd - 1
		case 'f':
			prec = max(digs.nd-digs.dp, 0)
		case 'g', 'G':
			prec = digs.nd
		}
	} else {
		// Round appropriately.
		switch fmt {
		case 'e', 'E':
			d.Round(prec + 1)
		case 'f':
			d.Round(d.dp + prec)
		case 'g', 'G':
			if prec == 0 {
				prec = 1
			}
			d.Round(prec)
		}
		digs = decimalSlice{d: d.d[:], nd: d.nd, dp: d.dp}
	}
	return formatDigits(dst, shortest, neg, digs, prec, fmt)
}
359683
func (p *PercentilesBucketAggregation) Percents(percents ...float64) *PercentilesBucketAggregation {
	p.percents = percents
	return p
}
1039751
func Parse(value string) (s Size, err error) {
	var (
		i    int
		r    rune
		num  float64
		unit string
	)

	for i, r = range value {
		if (r < '0' || r > '9') && r != '.' {
			break
		}
	}

	if num, err = strconv.ParseFloat(value[:i], 64); err != nil {
		return
	}

	unit = strings.TrimSpace(value[i:])
	switch unit {
	case "", "B":
		s = Size(num * B)
	case "K", "KB":
		s = Size(num * KB)
	case "M", "MB":
		s = Size(num * MB)
	case "G", "GB":
		s = Size(num * GB)
	case "T", "TB":
		s = Size(num * TB)
	case "P", "PB":
		s = Size(num * PB)
	case "E", "EB":
		s = Size(num * EB)
	default:
		err = errors.New("invalid value: " + value)
	}
	return
}
1026051
func ToFloat64(x interface{}) (float64, bool) {
	var xf float64
	xok := true

	switch xn := x.(type) {
	case uint8:
		xf = float64(xn)
	case uint16:
		xf = float64(xn)
	case uint32:
		xf = float64(xn)
	case uint64:
		xf = float64(xn)
	case int:
		xf = float64(xn)
	case int8:
		xf = float64(xn)
	case int16:
		xf = float64(xn)
	case int32:
		xf = float64(xn)
	case int64:
		xf = float64(xn)
	case float32:
		xf = float64(xn)
	case float64:
		xf = float64(xn)
	default:
		xok = false
	}

	return xf, xok
}
1052623
func Dema(real []float64, timePeriod int32) []float64 {
	var outBegIdx C.int
	var outNBElement C.int
	outReal := make([]float64, len(real))
	C.TA_DEMA(0, C.int(len(real)-1), (*C.double)(unsafe.Pointer(&real[0])), C.int(timePeriod), &outBegIdx, &outNBElement, (*C.double)(unsafe.Pointer(&outReal[0])))
	return outReal[:outNBElement]
}
954697
func bigauss(n1, n2 int, s1, a1, s2, a2, l, u float64) []float64 {
	points := make([]float64, n1+n2)
	for i := 0; i < n1; i++ {
		x := rand.NormFloat64()*s1 + a1
		for x < l || x > u {
			x = rand.NormFloat64()*s1 + a1
		}
		points[i] = x
	}
	for i := n1; i < n1+n2; i++ {
		x := rand.NormFloat64()*s2 + a2
		for x < l || x > u {
			x = rand.NormFloat64()*s2 + a2
		}
		points[i] = x
	}
	return points
}