diff --git a/FastRng/Double/Distributions/ChiSquare.cs b/FastRng/Double/Distributions/ChiSquare.cs index 3d70e97..fcf0727 100644 --- a/FastRng/Double/Distributions/ChiSquare.cs +++ b/FastRng/Double/Distributions/ChiSquare.cs @@ -1,3 +1,4 @@ +using System; using System.Threading; using System.Threading.Tasks; @@ -24,7 +25,7 @@ namespace FastRng.Double.Distributions public async ValueTask GetDistributedValue(CancellationToken token) { if (this.Random == null) - return 0.0; + return System.Double.NaN; return await this.Random.NextNumber(new Gamma{ Shape = 0.5 * this.DegreesOfFreedom, Scale = 2.0 }, token); } diff --git a/FastRng/Double/Distributions/Exponential.cs b/FastRng/Double/Distributions/Exponential.cs index 9a017b1..c390e5d 100644 --- a/FastRng/Double/Distributions/Exponential.cs +++ b/FastRng/Double/Distributions/Exponential.cs @@ -25,7 +25,7 @@ namespace FastRng.Double.Distributions public async ValueTask GetDistributedValue(CancellationToken token) { if (this.Random == null) - return 0.0; + return System.Double.NaN; if(this.Mean == 1.0) return -Math.Log(await this.Random.GetUniform(token)); diff --git a/FastRng/Double/Distributions/Gamma.cs b/FastRng/Double/Distributions/Gamma.cs index dc9f90a..f927207 100644 --- a/FastRng/Double/Distributions/Gamma.cs +++ b/FastRng/Double/Distributions/Gamma.cs @@ -29,7 +29,7 @@ namespace FastRng.Double.Distributions public async ValueTask GetDistributedValue(CancellationToken token) { if (this.Random == null) - return 0.0; + return System.Double.NaN; // Implementation based on "A Simple Method for Generating Gamma Variables" // by George Marsaglia and Wai Wan Tsang. ACM Transactions on Mathematical Software diff --git a/FastRng/Double/Distributions/Normal.cs b/FastRng/Double/Distributions/Normal.cs index 403b45a..3d05b7a 100644 --- a/FastRng/Double/Distributions/Normal.cs +++ b/FastRng/Double/Distributions/Normal.cs @@ -27,7 +27,7 @@ namespace FastRng.Double.Distributions public async ValueTask GetDistributedValue(CancellationToken token = default) { if (this.Random == null) - return 0.0; + return System.Double.NaN; var u1 = await this.Random.GetUniform(token); var u2 = await this.Random.GetUniform(token); diff --git a/FastRng/Double/Distributions/Uniform.cs b/FastRng/Double/Distributions/Uniform.cs index 6fa8682..784464d 100644 --- a/FastRng/Double/Distributions/Uniform.cs +++ b/FastRng/Double/Distributions/Uniform.cs @@ -7,6 +7,6 @@ namespace FastRng.Double.Distributions { public IRandom Random { get; set; } - public async ValueTask GetDistributedValue(CancellationToken token = default) => this.Random == null ? 0.0 : await this.Random.GetUniform(token); + public async ValueTask GetDistributedValue(CancellationToken token = default) => this.Random == null ? System.Double.NaN : await this.Random.GetUniform(token); } } \ No newline at end of file