Пример #1
0
        /// <summary>
        /// Computes PI.
        /// </summary>
        /// <param name="decimalPrecision">The decimal precision.</param>
        /// <returns></returns>
        private static string ComputePi(int decimalPrecision)
        {
            var x = new SuperDecimal(0, decimalPrecision);
            var y = new SuperDecimal(0, decimalPrecision);

            x = x.ArcTan(16, 5);
            y = y.ArcTan(4, 239);
            x = x - y;

            return(x.ToString());
        }
Пример #2
0
        /// <summary>
        /// Assigns the value.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <exception cref="Exception">SuperDecimal numbers provided cannot operate together.</exception>
        public void AssignValue(SuperDecimal value)
        {
            if (!IsValidForOperators(value))
            {
                throw new Exception("SuperDecimal numbers provided cannot operate together.");
            }

            for (int i = 0; i < _arraySize; i++)
            {
                _superDecimal[i] = value.Array[i];
            }
        }
Пример #3
0
        /// <summary>
        /// Determines whether a SuperDecimal can apply operations against another.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <returns>
        ///   <c>true</c> if [is valid for operators] [the specified value]; otherwise, <c>false</c>.
        /// </returns>
        public bool IsValidForOperators(SuperDecimal value)
        {
            // Cannot operate with itself
            if (Object.ReferenceEquals(this, value))
            {
                return(false);
            }

            // Have to be the same size
            if (value.DecimalCount != _decimalCount)
            {
                return(false);
            }

            return(true);
        }
Пример #4
0
        /// <summary>
        /// Compute the arc tangent result.
        /// </summary>
        /// <param name="multiplicand">The multiplicand.</param>
        /// <param name="reciprocal">The reciprocal.</param>
        public SuperDecimal ArcTan(UInt32 multiplicand, UInt32 reciprocal)
        {
            SuperDecimal result = new SuperDecimal(0, _decimalCount);

            SuperDecimal X = new SuperDecimal(multiplicand, _decimalCount);

            X           = X / reciprocal;
            reciprocal *= reciprocal;

            result.AssignValue(X);

            SuperDecimal term         = new SuperDecimal(0, _decimalCount);
            UInt32       divisor      = 1;
            bool         subtractTerm = true;

            while (true)
            {
                X = X / reciprocal;
                term.AssignValue(X);

                divisor += 2;

                term = term / divisor;
                if (term.IsZero())
                {
                    break;
                }

                if (subtractTerm)
                {
                    result = result - term;
                }
                else
                {
                    result = result + term;
                }

                subtractTerm = !subtractTerm;
            }

            return(result);
        }
Пример #5
0
        public override string ToString()
        {
            SuperDecimal temp = new SuperDecimal(0, _decimalCount);

            temp.AssignValue(this);

            StringBuilder sb = new StringBuilder();

            sb.Append(temp.Array[0]);
            sb.Append(System.Globalization.CultureInfo.CurrentCulture.NumberFormat.CurrencyDecimalSeparator);

            int digitCount = 0;

            while (digitCount < _decimalCount)
            {
                temp.Array[0] = 0;
                temp          = temp * 100000;
                sb.AppendFormat("{0:D5}", temp.Array[0]);
                digitCount += 5;
            }

            return(sb.ToString());
        }