MCPcopy Index your code
hub / github.com/google/mangle / evalAvg

Function evalAvg

functional/functional.go:1439–1458  ·  view source on GitHub ↗
(it iter.Seq[ast.Constant])

Source from the content-addressed store, hash-verified

1437}
1438
1439func evalAvg(it iter.Seq[ast.Constant]) (ast.Constant, error) {
1440 var sum float64
1441 var n int
1442 for c := range it {
1443 n++
1444 num, err := c.Float64Value()
1445 if err != nil {
1446 fnum, err := c.NumberValue()
1447 if err != nil {
1448 return ast.Constant{}, err
1449 }
1450 num = float64(fnum)
1451 }
1452 sum += num
1453 }
1454 if n == 0 {
1455 return ast.Float64(math.NaN()), nil
1456 }
1457 return ast.Float64(sum / float64(n)), nil
1458}

Callers 1

EvalReduceFnFunction · 0.85

Calls 3

Float64Function · 0.92
Float64ValueMethod · 0.80
NumberValueMethod · 0.80

Tested by

no test coverage detected