Skip to content

Commit 8de72e7

Browse files
authored
Check for infinity, it creates trouble (#15)
1 parent 3a82c69 commit 8de72e7

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

varopt.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ type Varopt struct {
4343
// passed in separately.
4444
type Sample interface{}
4545

46-
var ErrInvalidWeight = fmt.Errorf("Negative, zero, or NaN weight")
46+
var ErrInvalidWeight = fmt.Errorf("Negative, Zero, Inf or NaN weight")
4747

4848
// New returns a new Varopt sampler with given capacity (i.e.,
4949
// reservoir size) and random number generator.
@@ -78,7 +78,7 @@ func (s *Varopt) Add(sample Sample, weight float64) (Sample, error) {
7878
Weight: weight,
7979
}
8080

81-
if weight <= 0 || math.IsNaN(weight) {
81+
if weight <= 0 || math.IsNaN(weight) || math.IsInf(weight, 1) {
8282
return nil, ErrInvalidWeight
8383
}
8484

0 commit comments

Comments
 (0)