From 8de72e7fedb787571ca65e12cdfe33fde01a485b Mon Sep 17 00:00:00 2001 From: Joshua MacDonald Date: Tue, 13 Jul 2021 16:24:45 -0700 Subject: [PATCH] Check for infinity, it creates trouble (#15) --- varopt.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/varopt.go b/varopt.go index f573850..dbe605b 100644 --- a/varopt.go +++ b/varopt.go @@ -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. @@ -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 }