From b1dfeaec20ad3cdb1398072758043dfa46693f4f Mon Sep 17 00:00:00 2001 From: Thorsten Sommer Date: Sat, 26 Sep 2020 11:49:50 +0200 Subject: [PATCH] Optimization --- FastRng/Double/Distributions/Exponential.cs | 2 +- FastRng/Double/Distributions/Gamma.cs | 2 +- FastRng/Double/Distributions/Normal.cs | 2 +- FastRng/Double/Distributions/Uniform.cs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/FastRng/Double/Distributions/Exponential.cs b/FastRng/Double/Distributions/Exponential.cs index 6a44ee0..ec5102e 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; + return 0.0; if(this.Mean == 1) return -Math.Log(await this.Random.GetUniform(token)); diff --git a/FastRng/Double/Distributions/Gamma.cs b/FastRng/Double/Distributions/Gamma.cs index 65200b7..73885f7 100644 --- a/FastRng/Double/Distributions/Gamma.cs +++ b/FastRng/Double/Distributions/Gamma.cs @@ -27,7 +27,7 @@ namespace FastRng.Double.Distributions public async ValueTask GetDistributedValue(CancellationToken token) { if (this.Random == null) - return 0; + return 0.0; // 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 efb4e35..99521ab 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; + return 0.0; 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 79b9d42..6fa8682 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 : await this.Random.GetUniform(token); + public async ValueTask GetDistributedValue(CancellationToken token = default) => this.Random == null ? 0.0 : await this.Random.GetUniform(token); } } \ No newline at end of file