Using NaN instead of 0.0
This commit is contained in:
		
							parent
							
								
									9ba0eb9478
								
							
						
					
					
						commit
						30457a7f62
					
				@ -1,3 +1,4 @@
 | 
				
			|||||||
 | 
					using System;
 | 
				
			||||||
using System.Threading;
 | 
					using System.Threading;
 | 
				
			||||||
using System.Threading.Tasks;
 | 
					using System.Threading.Tasks;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -24,7 +25,7 @@ namespace FastRng.Double.Distributions
 | 
				
			|||||||
        public async ValueTask<double> GetDistributedValue(CancellationToken token)
 | 
					        public async ValueTask<double> GetDistributedValue(CancellationToken token)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            if (this.Random == null)
 | 
					            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);
 | 
					            return await this.Random.NextNumber(new Gamma{ Shape = 0.5 * this.DegreesOfFreedom, Scale = 2.0 }, token);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
				
			|||||||
@ -25,7 +25,7 @@ namespace FastRng.Double.Distributions
 | 
				
			|||||||
        public async ValueTask<double> GetDistributedValue(CancellationToken token)
 | 
					        public async ValueTask<double> GetDistributedValue(CancellationToken token)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            if (this.Random == null)
 | 
					            if (this.Random == null)
 | 
				
			||||||
                return 0.0;
 | 
					                return System.Double.NaN;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if(this.Mean == 1.0)
 | 
					            if(this.Mean == 1.0)
 | 
				
			||||||
                return -Math.Log(await this.Random.GetUniform(token));
 | 
					                return -Math.Log(await this.Random.GetUniform(token));
 | 
				
			||||||
 | 
				
			|||||||
@ -29,7 +29,7 @@ namespace FastRng.Double.Distributions
 | 
				
			|||||||
        public async ValueTask<double> GetDistributedValue(CancellationToken token)
 | 
					        public async ValueTask<double> GetDistributedValue(CancellationToken token)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            if (this.Random == null)
 | 
					            if (this.Random == null)
 | 
				
			||||||
                return 0.0;
 | 
					                return System.Double.NaN;
 | 
				
			||||||
            
 | 
					            
 | 
				
			||||||
            // Implementation based on "A Simple Method for Generating Gamma Variables"
 | 
					            // Implementation based on "A Simple Method for Generating Gamma Variables"
 | 
				
			||||||
            // by George Marsaglia and Wai Wan Tsang.  ACM Transactions on Mathematical Software
 | 
					            // by George Marsaglia and Wai Wan Tsang.  ACM Transactions on Mathematical Software
 | 
				
			||||||
 | 
				
			|||||||
@ -27,7 +27,7 @@ namespace FastRng.Double.Distributions
 | 
				
			|||||||
        public async ValueTask<double> GetDistributedValue(CancellationToken token = default)
 | 
					        public async ValueTask<double> GetDistributedValue(CancellationToken token = default)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            if (this.Random == null)
 | 
					            if (this.Random == null)
 | 
				
			||||||
                return 0.0;
 | 
					                return System.Double.NaN;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            var u1 = await this.Random.GetUniform(token);
 | 
					            var u1 = await this.Random.GetUniform(token);
 | 
				
			||||||
            var u2 = await this.Random.GetUniform(token);
 | 
					            var u2 = await this.Random.GetUniform(token);
 | 
				
			||||||
 | 
				
			|||||||
@ -7,6 +7,6 @@ namespace FastRng.Double.Distributions
 | 
				
			|||||||
    {
 | 
					    {
 | 
				
			||||||
        public IRandom Random { get; set; }
 | 
					        public IRandom Random { get; set; }
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        public async ValueTask<double> GetDistributedValue(CancellationToken token = default) => this.Random == null ? 0.0 : await this.Random.GetUniform(token);
 | 
					        public async ValueTask<double> GetDistributedValue(CancellationToken token = default) => this.Random == null ? System.Double.NaN : await this.Random.GetUniform(token);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user