Beispiel #1
0
        /// <summary>
        /// Returns the <see cref="T:System.Double" /> negative binomial distribution.
        /// </summary>
        /// <param name="args"><para>
        /// The args contains 3 items: number_f, number_s, probability_s.
        /// </para>
        /// <para>
        /// Number_f is the number of failures.
        /// </para>
        /// <para>
        /// Number_s is the threshold number of successes.
        /// </para>
        /// <para>
        /// Probability_s is the probability of a success.
        /// </para></param>
        /// <returns>
        /// A <see cref="T:System.Double" /> value that indicates the evaluate result.
        /// </returns>
        public override object Evaluate(object[] args)
        {
            int    num;
            int    num2;
            double num3;

            base.CheckArgumentsLength(args);
            if (!CalcConvert.TryToInt(args[0], out num) || !CalcConvert.TryToInt(args[1], out num2))
            {
                return(CalcErrors.Value);
            }
            if (!CalcConvert.TryToDouble(args[2], out num3, true))
            {
                return(CalcErrors.Value);
            }
            if ((num3 < 0.0) || (num3 >= 1.0))
            {
                return(CalcErrors.Number);
            }
            if (((num + num2) - 1) <= 0)
            {
                return(CalcErrors.Number);
            }
            object obj2 = new CalcCombinFunction().Evaluate(new object[] { (int)((num + num2) - 1), (int)(num2 - 1) });

            if (obj2 is CalcError)
            {
                return(obj2);
            }
            double num4 = (double)((double)obj2);
            double num5 = Math.Pow(num3, (double)num2);
            double num6 = Math.Pow(1.0 - num3, (double)num);

            return(CalcConvert.ToResult((num4 * num5) * num6));
        }
Beispiel #2
0
        /// <summary>
        /// Returns the <see cref="T:System.Double" /> hyper geometric distribution for a finite population.
        /// </summary>
        /// <param name="args"><para>
        /// The args contains 4 items: sample_s, number_sample, population_s, number_population.
        /// </para>
        /// <para>
        /// Sample_s is the number of successes in the sample.
        /// </para>
        /// <para>
        /// Number_sample is the size of the sample.
        /// </para>
        /// <para>
        /// Population_s is the number of successes in the population.
        /// </para>
        /// <para>
        /// Number_population is the population size.
        /// </para></param>
        /// <returns>
        /// A <see cref="T:System.Double" /> value that indicates the evaluate result.
        /// </returns>
        public override object Evaluate(object[] args)
        {
            base.CheckArgumentsLength(args);
            int num  = CalcConvert.ToInt(args[0]);
            int num2 = CalcConvert.ToInt(args[1]);
            int num3 = CalcConvert.ToInt(args[2]);
            int num4 = CalcConvert.ToInt(args[3]);

            if ((num < 0.0) || (num > Math.Min(num2, num3)))
            {
                return(CalcErrors.Number);
            }
            if (num < Math.Max((double)0.0, (double)((num2 - num4) + num3)))
            {
                return(CalcErrors.Number);
            }
            if ((num2 < 0.0) || (num2 > num4))
            {
                return(CalcErrors.Number);
            }
            if ((num3 < 0.0) || (num3 > num4))
            {
                return(CalcErrors.Number);
            }
            if (num4 < 0.0)
            {
                return(CalcErrors.Number);
            }
            CalcBuiltinFunction function = new CalcCombinFunction();
            object obj2 = function.Evaluate(new object[] { (int)num3, (int)num });

            if (obj2 is CalcError)
            {
                return(obj2);
            }
            double num5 = (double)((double)obj2);

            obj2 = function.Evaluate(new object[] { (int)(num4 - num3), (int)(num2 - num) });
            if (obj2 is CalcError)
            {
                return(obj2);
            }
            double num6 = (double)((double)obj2);

            obj2 = function.Evaluate(new object[] { (int)num4, (int)num2 });
            if (obj2 is CalcError)
            {
                return(obj2);
            }
            double num7 = (double)((double)obj2);

            return(CalcConvert.ToResult((num5 * num6) / num7));
        }