From d5404d65c85022a37d0b172f3a715e4f040ef8de Mon Sep 17 00:00:00 2001 From: Thorsten Sommer Date: Sat, 31 Oct 2020 22:11:20 +0100 Subject: [PATCH] Fixed case when operation gets cancelled --- FastRng/Double/ShapeFitter.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/FastRng/Double/ShapeFitter.cs b/FastRng/Double/ShapeFitter.cs index 6fe2ff8..dc8ee13 100644 --- a/FastRng/Double/ShapeFitter.cs +++ b/FastRng/Double/ShapeFitter.cs @@ -43,9 +43,14 @@ namespace FastRng.Double while (!token.IsCancellationRequested) { var x = await this.rng.GetUniform(token); + if (double.IsNaN(x)) + return x; + var nextBucket = (int)Math.Floor(x * this.sampleSize); var threshold = this.probabilities[nextBucket]; var y = await this.rng.NextNumber(0.0d, this.max, this.uniform, token); + if (double.IsNaN(y)) + return y; if(y > threshold) continue;