Ejemplo n.º 1
0
        /// <summary>
        /// Returns the <see cref="T:System.String" /> number converted from octal to binary.
        /// </summary>
        /// <param name="args"><para>
        /// The args contains 1 - 2 items: number, [places].
        /// </para>
        /// <para>
        /// Number is the octal number you want to convert.
        /// Number may not contain more than 10 characters.
        /// The most significant bit of number is the sign bit.
        /// The remaining 29 bits are magnitude bits.
        /// Negative numbers are represented using two's-complement notation.
        /// </para>
        /// <para>
        /// Places is the number of characters to use.
        /// If places is omitted, OCT2BIN uses the minimum number of characters necessary.
        /// Places is useful for padding the return value with leading 0s (zeros).
        /// </para></param>
        /// <returns>
        /// A <see cref="T:System.String" /> value that indicates the evaluate result.
        /// </returns>
        public override object Evaluate(object[] args)
        {
            int num3;

            base.CheckArgumentsLength(args);
            string s   = CalcConvert.ToString(args[0]);
            int    num = CalcHelper.ArgumentExists(args, 1) ? CalcConvert.ToInt(args[1]) : 1;

            if (10 < s.Length)
            {
                return(CalcErrors.Number);
            }
            if ((num < 1) || (10 < num))
            {
                return(CalcErrors.Number);
            }
            long number = EngineeringHelper.StringToLong(s, 8, out num3);

            if (num3 < s.Length)
            {
                return(CalcErrors.Number);
            }
            if ((number < -512L) || (0x1ffL < number))
            {
                return(CalcErrors.Number);
            }
            string str2 = EngineeringHelper.LongToString(number, 2L, (long)num);

            if (((0L <= number) && (num < str2.Length)) && CalcHelper.ArgumentExists(args, 1))
            {
                return(CalcErrors.Number);
            }
            return(str2);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns the <see cref="T:System.Double" /> natural logarithm of the gamma function, ¦£(x).
        /// </summary>
        /// <param name="args"><para>
        /// The args contains 1 item: x.
        /// </para>
        /// <para>
        /// X is the value for which you want to calculate GAMMALN.
        /// </para></param>
        /// <returns>
        /// A <see cref="T:System.Double" /> value that indicates the evaluate result.
        /// </returns>
        public override object Evaluate(object[] args)
        {
            double num;

            base.CheckArgumentsLength(args);
            if (!CalcConvert.TryToDouble(args[0], out num, true))
            {
                return(CalcErrors.Value);
            }
            if (num <= 0.0)
            {
                return(CalcErrors.Number);
            }
            return((double)EngineeringHelper.lgamma(num));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Returns the <see cref="T:System.Double" /> modified Bessel function represented by J(x).
        /// </summary>
        /// <param name="args"><para>
        /// The args contains 2 items: x, n.
        /// </para>
        /// <para>
        /// X is the value at which to evaluate the function.
        /// </para>
        /// <para>
        /// N is the order of the Bessel function. If n is not an integer, it is truncated.
        /// </para></param>
        /// <returns>
        /// A <see cref="T:System.Double" /> value that indicates the evaluate result.
        /// </returns>
        public override object Evaluate(object[] args)
        {
            double num;

            base.CheckArgumentsLength(args);
            if (!CalcConvert.TryToDouble(args[0], out num, true))
            {
                return(CalcErrors.Value);
            }
            int order = CalcConvert.ToInt(args[1]);

            if (order < 0)
            {
                return(CalcErrors.Number);
            }
            return(CalcConvert.ToResult(EngineeringHelper.Bessel(num, order, false)));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Returns the <see cref="T:System.Double" /> number converted from hexadecimal to decimal.
        /// </summary>
        /// <param name="args"><para>
        /// The args contains 1 item: number.
        /// </para>
        /// <para>
        /// Number is the hexadecimal number you want to convert.
        /// Number cannot contain more than 10 characters (40 bits).
        /// The most significant bit of number is the sign bit.
        /// The remaining 39 bits are magnitude bits.
        /// Negative numbers are represented using two's-complement notation.
        /// </para></param>
        /// <returns>
        /// A <see cref="T:System.Object" /> value that indicates the evaluate result.
        /// </returns>
        public override object Evaluate(object[] args)
        {
            int num2;

            base.CheckArgumentsLength(args);
            string s = CalcConvert.ToString(args[0]);

            if (10 < s.Length)
            {
                return(CalcErrors.Number);
            }
            long num = EngineeringHelper.StringToLong(s, 0x10, out num2);

            if (num2 < s.Length)
            {
                return(CalcErrors.Number);
            }
            return(CalcConvert.ToResult((double)num));
        }
Ejemplo n.º 5
0
        internal double lbeta(double a, double b)
        {
            double num;
            double num3;
            double x = num3 = a;

            if (b < x)
            {
                x = b;
            }
            if (b > num3)
            {
                num3 = b;
            }
            if (x < 0.0)
            {
                return(double.NaN);
            }
            if (x == 0.0)
            {
                return(double.MaxValue);
            }
            if (x >= 10.0)
            {
                num = (this.lgammacor(x) + this.lgammacor(num3)) - this.lgammacor(x + num3);
                return(((((Math.Log(num3) * -0.5) + 0.91893853320467278) + num) + ((x - 0.5) * Math.Log(x / (x + num3)))) + (num3 * this.logrelerr(-x / (x + num3))));
            }
            if (num3 >= 10.0)
            {
                num = this.lgammacor(num3) - this.lgammacor(x + num3);
                object obj2 = new CalcGammaLnFunction().Evaluate(new object[] { (double)x });
                if (obj2 is CalcError)
                {
                    return(double.NaN);
                }
                return((((((double)obj2) + num) + x) - (x * Math.Log(x + num3))) + ((num3 - 0.5) * this.logrelerr(-x / (x + num3))));
            }
            double num4 = EngineeringHelper.gamma(x);
            double num5 = EngineeringHelper.gamma(num3);
            double num6 = EngineeringHelper.gamma(x + num3);

            return(Math.Log(num4 * (num5 / num6)));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Returns the <see cref="T:System.Int32" /> converted from binary to decimal.
        /// </summary>
        /// <param name="args"><para>
        /// The args contains 1 item: number.
        /// </para>
        /// <para>
        /// Number is the binary number you want to convert.
        /// Number cannot contain more than 10 characters (10 bits).
        /// The most significant bit of number is the sign bit.
        /// The remaining 9 bits are magnitude bits.
        /// Negative numbers are represented using two's-complement notation.
        /// </para></param>
        /// <returns>
        /// A <see cref="T:System.Int32" /> value that indicates the evaluate result.
        /// </returns>
        public override object Evaluate(object[] args)
        {
            int num2;

            base.CheckArgumentsLength(args);
            string s = CalcConvert.ToString(args[0]);

            if (s.Length > 10)
            {
                return(CalcErrors.Number);
            }
            long num = EngineeringHelper.StringToLong(s, 2, out num2);

            if (s.Length > num2)
            {
                return(CalcErrors.Number);
            }
            return((int)CalcConvert.ToInt((long)num));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Returns the <see cref="T:System.Double" /> Bessel function, which is also called the Weber function or the Neumann function.
        /// </summary>
        /// <param name="args"><para>
        /// The args contains 2 items: x, n.
        /// </para>
        /// <para>
        /// X is the value at which to evaluate the function.
        /// </para>
        /// <para>
        /// N is the order of the function. If n is not an integer, it is truncated.
        /// </para></param>
        /// <returns>
        /// A <see cref="T:System.Double" /> value that indicates the evaluate result.
        /// </returns>
        public override object Evaluate(object[] args)
        {
            double num;

            base.CheckArgumentsLength(args);
            if (!CalcConvert.TryToDouble(args[0], out num, true))
            {
                return(CalcErrors.Value);
            }
            int n = CalcConvert.ToInt(args[1]);

            if (num <= 0.0)
            {
                return(CalcErrors.Number);
            }
            if (n < 0)
            {
                return(CalcErrors.Number);
            }
            return(CalcConvert.ToResult(EngineeringHelper.yn(n, num)));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Returns the <see cref="T:System.String" /> converted from decimal to hexadecimal.
        /// </summary>
        /// <param name="args"><para>
        /// The args contains 1 - 2 items: number, [places].
        /// </para>
        /// <para>
        /// Number is the decimal integer you want to convert.
        /// If number is negative, places is ignored and DEC2HEX returns
        /// a 10-character (40-bit) hexadecimal number in which the most significant bit is the sign bit.
        /// The remaining 39 bits are magnitude bits.
        /// Negative numbers are represented using two's-complement notation.
        /// </para>
        /// <para>
        /// Places is the number of characters to use.
        /// If places is omitted, DEC2HEX uses the minimum number of characters necessary.
        /// Places is useful for padding the return value with leading 0s (zeros).
        /// </para></param>
        /// <returns>
        /// A <see cref="T:System.String" /> value that indicates the evaluate result.
        /// </returns>
        public override object Evaluate(object[] args)
        {
            base.CheckArgumentsLength(args);
            long number = CalcConvert.ToLong(args[0]);
            int  num2   = CalcHelper.ArgumentExists(args, 1) ? CalcConvert.ToInt(args[1]) : 1;

            if ((number < -549755813888L) || (0x7fffffffffL < number))
            {
                return(CalcErrors.Number);
            }
            if ((num2 < 1) || (10 < num2))
            {
                return(CalcErrors.Number);
            }
            string str = EngineeringHelper.LongToString(number, 0x10L, (long)num2);

            if (((0L <= number) && (num2 < str.Length)) && CalcHelper.ArgumentExists(args, 1))
            {
                return(CalcErrors.Number);
            }
            return(str);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Returns the <see cref="T:System.Double" /> gamma distribution.
        /// </summary>
        /// <param name="args"><para>
        /// The args contains 4 items: x, alpha, beta, cumulative.
        /// </para>
        /// <para>
        /// X is the value at which you want to evaluate the distribution.
        /// </para>
        /// <para>
        /// Alpha is a parameter to the distribution.
        /// </para>
        /// <para>
        /// Beta is a parameter to the distribution. If beta = 1, GAMMADIST returns the standard gamma distribution.
        /// </para>
        /// <para>
        /// Cumulative is a logical value that determines the form of the function. If cumulative is TRUE, GAMMADIST returns the cumulative distribution function; if FALSE, it returns the probability density function.
        /// </para></param>
        /// <returns>
        /// A <see cref="T:System.Double" /> value that indicates the evaluate result.
        /// </returns>
        public override object Evaluate(object[] args)
        {
            double num;
            double num2;
            double num3;
            bool   flag;
            double num9;
            double num15;
            double num16;
            double num18;
            double num21;

            base.CheckArgumentsLength(args);
            if ((!CalcConvert.TryToDouble(args[0], out num, true) || !CalcConvert.TryToDouble(args[1], out num2, true)) || !CalcConvert.TryToDouble(args[2], out num3, true))
            {
                return(CalcErrors.Value);
            }
            if (!CalcConvert.TryToBool(args[3], out flag))
            {
                return(CalcErrors.Value);
            }
            if (((num < 0.0) || (num2 <= 0.0)) || (num3 <= 0.0))
            {
                return(CalcErrors.Number);
            }
            if (!flag)
            {
                double d = Math.Pow(num3, num2);
                if (double.IsNaN(d) || double.IsInfinity(d))
                {
                    return(CalcErrors.DivideByZero);
                }
                double num5 = 1.0 / (d * EngineeringHelper.gamma(num2));
                double num6 = Math.Pow(num, num2 - 1.0);
                double num7 = Math.Exp(-(num / num3));
                double num8 = num6 * num7;
                return((double)(num5 * num8));
            }
            double y     = 0.33333333333333331;
            double num23 = 100000000.0;
            double num24 = 1E+37;
            double num25 = 1000.0;
            double num26 = -88.0;

            num /= num3;
            if (num <= 0.0)
            {
                return(CalcErrors.Number);
            }
            if (num2 > num25)
            {
                CalcBuiltinFunction function = new CalcNormDistFunction();
                num9 = (Math.Sqrt(num2) * 3.0) * ((Math.Pow(num / num2, y) + (1.0 / (num2 * 9.0))) - 1.0);
                object obj2 = function.Evaluate(new object[] { (double)num9, (double)0.0, (double)1.0, (bool)true });
                if (obj2 is CalcError)
                {
                    return(obj2);
                }
                return((double)obj2);
            }
            if (num > num23)
            {
                return((double)1.0);
            }
            if ((num <= 1.0) || (num < num2))
            {
                object obj3 = new CalcGammaLnFunction().Evaluate(new object[] { (double)(num2 + 1.0) });
                if (obj3 is CalcError)
                {
                    return(obj3);
                }
                num15 = ((num2 * Math.Log(num)) - num) - ((double)obj3);
                num16 = 1.0;
                num21 = 1.0;
                num18 = num2;
                do
                {
                    num18++;
                    num16  = (num16 * num) / num18;
                    num21 += num16;
                }while (num16 > 2.2204460492503131E-16);
                num15 += Math.Log(num21);
                num21  = 0.0;
                if (num15 >= num26)
                {
                    num21 = Math.Exp(num15);
                }
            }
            else
            {
                object obj4 = new CalcGammaLnFunction().Evaluate(new object[] { (double)num2 });
                if (obj4 is CalcError)
                {
                    return(obj4);
                }
                num15 = ((num2 * Math.Log(num)) - num) - ((double)obj4);
                num18 = 1.0 - num2;
                double num19 = (num18 + num) + 1.0;
                num16 = 0.0;
                num9  = 1.0;
                double num10 = num;
                double num11 = num + 1.0;
                double num12 = num * num19;
                num21 = num11 / num12;
                while (true)
                {
                    num18++;
                    num19 += 2.0;
                    num16++;
                    double num20 = num18 * num16;
                    double num13 = (num19 * num11) - (num20 * num9);
                    double num14 = (num19 * num12) - (num20 * num10);
                    if (Math.Abs(num14) > 0.0)
                    {
                        double num17 = num13 / num14;
                        if (Math.Abs((double)(num21 - num17)) <= Math.Min((double)2.2204460492503131E-16, (double)(2.2204460492503131E-16 * num17)))
                        {
                            break;
                        }
                        num21 = num17;
                    }
                    num9  = num11;
                    num10 = num12;
                    num11 = num13;
                    num12 = num14;
                    if (Math.Abs(num13) >= num24)
                    {
                        num9  /= num24;
                        num10 /= num24;
                        num11 /= num24;
                        num12 /= num24;
                    }
                }
                num15 += Math.Log(num21);
                num21  = 1.0;
                if (num15 >= num26)
                {
                    num21 = 1.0 - Math.Exp(num15);
                }
            }
            return((double)num21);
        }