Ejemplo n.º 1
0
 /// <summary>
 /// Computes the logarithm of the Beta function.
 /// </summary>
 /// <param name="a">The first parameter, which must be positive.</param>
 /// <param name="b">The second parameter, which must be positive.</param>
 /// <returns>The value of ln(B(a,b)).</returns>
 /// <remarks>
 /// <para>This function accurately computes ln(B(a,b)) even for values of a and b for which B(a,b) is
 /// too small or large to be represented by a double.</para>
 /// </remarks>
 /// <exception cref="ArgumentOutOfRangeException"><paramref name="a"/> or <paramref name="b"/> is negative or zero.</exception>
 /// <seealso cref="Beta(System.Double,System.Double)"/>
 public static double LogBeta(double a, double b)
 {
     if ((a > 16.0) && (b > 16.0))
     {
         return(Stirling.LogBeta(a, b));
     }
     else if (a < 0.0)
     {
         throw new ArgumentOutOfRangeException(nameof(a));
     }
     else if (b < 0.0)
     {
         throw new ArgumentOutOfRangeException(nameof(b));
     }
     else if (Double.IsNaN(a) || Double.IsNaN(b))
     {
         return(Double.NaN);
     }
     else if (a == 0.0 || b == 0.0)
     {
         return(Double.PositiveInfinity);
     }
     else
     {
         return(Lanczos.LogBeta(a, b));
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Computes the lograrithm of the Beta function.
 /// </summary>
 /// <param name="a">The first parameter, which must be positive.</param>
 /// <param name="b">The second parameter, which must be positive.</param>
 /// <returns>The value of ln(B(a,b)).</returns>
 /// <remarks>
 /// <para>This function accurately computes ln(B(a,b)) even for values of a and b for which B(a,b) is
 /// too small or large to be represented by a double.</para>
 /// </remarks>
 /// <exception cref="ArgumentOutOfRangeException"><paramref name="a"/> or <paramref name="b"/> is non-positive.</exception>
 /// <seealso cref="Beta(System.Double,System.Double)"/>
 public static double LogBeta(double a, double b)
 {
     if (a <= 0.0)
     {
         throw new ArgumentOutOfRangeException("a");
     }
     if (b <= 0.0)
     {
         throw new ArgumentOutOfRangeException("b");
     }
     if ((a > 16.0) && (b > 16.0))
     {
         return(Stirling.LogBeta(a, b));
     }
     else
     {
         return(Lanczos.LogBeta(a, b));
     }
 }