// Average returns the float average of the values in the buffer.
354063
func (s Seq) Average() float64 {
	if s.Len() == 0 {
		return 0
	}

	return s.Sum() / float64(s.Len())
}
927225
func (lrs *LinearRegressionSeries) normalize(xvalue float64) float64 {
	return (xvalue - lrs.avgx) / lrs.stddevx
}
984224
func average(sum []uint64, w, h int, n uint64) *image.RGBA {
	ret := image.NewRGBA(image.Rect(0, 0, w, h))
	for y := 0; y < h; y++ {
		for x := 0; x < w; x++ {
			index := 4 * (y*w + x)
			pix := ret.Pix[y*ret.Stride+x*4:]
			pix[0] = uint8(sum[index+0] / n)
			pix[1] = uint8(sum[index+1] / n)
			pix[2] = uint8(sum[index+2] / n)
			pix[3] = uint8(sum[index+3] / n)
		}
	}
	return ret
}
556561
func ToFloat(value interface{}) float64 {
	if result := ToString(value); result == "" {
		return 0
	} else if i, err := strconv.ParseFloat(result, 64); err == nil {
		return i
	} else {
		panic("failed to parse float: " + result)
	}
}
323761
func asFloat(param string) (float64, error) {
	i, err := strconv.ParseFloat(param, 64)
	if err != nil {
		return 0.0, ErrBadParameter
	}
	return i, nil
}
930217
func (tr Row) Float(nn int) (val float64) {
	val, err := tr.FloatErr(nn)
	if err != nil {
		panic(err)
	}
	return
}
852883
func (buf *IntBuffer) AsFloat32Buffer() *Float32Buffer {
	newB := &Float32Buffer{}
	newB.Data = make([]float32, len(buf.Data))
	max := int64(0)
	// try to guess the bit depths without knowing the source
	if buf.SourceBitDepth == 0 {
		for _, s := range buf.Data {
			if int64(s) > max {
				max = int64(s)
			}
		}
		buf.SourceBitDepth = 8
		if max > 127 {
			buf.SourceBitDepth = 16
		}
		// greater than int16, expecting int24
		if max > 32767 {
			buf.SourceBitDepth = 24
		}
		// int 32
		if max > 8388607 {
			buf.SourceBitDepth = 32
		}
		// int 64
		if max > 4294967295 {
			buf.SourceBitDepth = 64
		}
	}
	newB.SourceBitDepth = buf.SourceBitDepth
	factor := math.Pow(2, float64(buf.SourceBitDepth)-1)
	for i := 0; i < len(buf.Data); i++ {
		newB.Data[i] = float32(float64(buf.Data[i]) / factor)
	}
	newB.Format = &Format{
		NumChannels: buf.Format.NumChannels,
		SampleRate:  buf.Format.SampleRate,
	}
	return newB
}
603066
func (data ChartUints) Avg(s, e int) uint64 {
	if e <= s {
		return 0
	}
	var sum uint64
	for _, v := range data[s:e] {
		sum += v
	}
	return sum / uint64(e-s)
}
22765
func (v *Value) Float() float64 {
	switch v.getResolvedValue().Kind() {
	case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
		return float64(v.getResolvedValue().Int())
	case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
		return float64(v.getResolvedValue().Uint())
	case reflect.Float32, reflect.Float64:
		return v.getResolvedValue().Float()
	case reflect.String:
		// Try to convert from string to float64 (base 10)
		f, err := strconv.ParseFloat(v.getResolvedValue().String(), 64)
		if err != nil {
			return 0.0
		}
		return f
	default:
		logf("Value.Float() not available for type: %s\n", v.getResolvedValue().Kind().String())
		return 0.0
	}
}
1279399
func ParseFloat(value string) float64 {
	f, _ := strconv.ParseFloat(value, 64)
	return f
}
1208111
func (i Int) Float() Float {
	// TODO(adonovan): opt: handle common values without allocation.
	f, _ := new(big.Float).SetInt(i.bigint).Float64()
	return Float(f)
}
795960
func norm(num, min, max int) int {
	if min > max {
		panic("min > max")
	}
	return int(math.Floor((float64(num-min) / float64(max-min) * 100) + 0.5))
}
286205
func ToFloat(str string) (float64, error) {
	res, err := strconv.ParseFloat(str, 64)
	if err != nil {
		res = 0.0
	}
	return res, err
}
206763
func ParseFloat(b []byte) (float64, error) {
	if v, err := parseFloat(&b); err != nil {
		return 0, MalformedValueError
	} else {
		return v, nil
	}
}
221330
func (gb GrainBuf) Rate(rate int8) Input {
	CheckRate(rate)
	if gb.BufNum == nil {
		panic("GrainBuf requires a buffer number")
	}
	(&gb).defaults()
	return NewInput("GrainBuf", rate, 0, gb.NumChannels, gb.Trigger, gb.Dur, gb.BufNum, gb.Speed, gb.Pos, gb.Interp, gb.Pan, gb.EnvBuf, gb.MaxGrains)
}
1105664
func (s Sample) Mean() float64 {
	if len(s.Xs) == 0 || s.Weights == nil {
		return Mean(s.Xs)
	}

	m, wsum := 0.0, 0.0
	for i, x := range s.Xs {
		// Use weighted incremental mean:
		//   m_i = (1 - w_i/wsum_i) * m_(i-1) + (w_i/wsum_i) * x_i
		//       = m_(i-1) + (x_i - m_(i-1)) * (w_i/wsum_i)
		w := s.Weights[i]
		wsum += w
		m += (x - m) * w / wsum
	}
	return m
}
130087
func (t *Tag) Float(i int) (float64, error) {
	if t.format != FloatVal {
		return 0, t.typeErr(FloatVal)
	}
	return t.floatVals[i], nil
}