(it iter.Seq[ast.Constant])
| 1437 | } |
| 1438 | |
| 1439 | func 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 | } |
no test coverage detected