Skip to content

Commit

Permalink
Check for infinity, it creates trouble (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmacd authored Jul 13, 2021
1 parent 3a82c69 commit 8de72e7
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions varopt.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type Varopt struct {
// passed in separately.
type Sample interface{}

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

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

if weight <= 0 || math.IsNaN(weight) {
if weight <= 0 || math.IsNaN(weight) || math.IsInf(weight, 1) {
return nil, ErrInvalidWeight
}

Expand Down

0 comments on commit 8de72e7

Please sign in to comment.