Example #1
0
        /// <summary>
        /// Calculates binary expressions and pushes the result into the operands stack
        /// </summary>
        /// <param name="op">Binary operator</param>
        /// <param name="operand1">First operand</param>
        /// <param name="operand2">Second operand</param>
        private void Calculate(string op, PrimesBigInteger operand1, PrimesBigInteger operand2)
        {
            PrimesBigInteger res = PrimesBigInteger.Zero;

            try
            {
                switch (op)
                {
                case Token.Add: res = operand1.Add(operand2); break;

                case Token.Subtract: res = operand1.Subtract(operand2); break;

                case Token.Multiply: res = operand1.Multiply(operand2); break;

                case Token.Divide: res = operand1.Divide(operand2); break;

                case Token.Mod: res = operand1.Mod(operand2); break;

                case Token.Power: res = operand1.Pow(operand2.IntValue); break;

                case Token.Log: res = PrimesBigInteger.Zero; break;

                case Token.Root: res = PrimesBigInteger.Zero; break;
                }

                operands.Push(PostProcess(res));
            }
            catch (Exception e)
            {
                ThrowException(e.Message);
            }
        }
Example #2
0
        public virtual PrimesBigInteger Execute(PrimesBigInteger input)
        {
            PrimesBigInteger a = (m_list[A] as PolynomFactor).Value;
            PrimesBigInteger b = (m_list[B] as PolynomFactor).Value;
            PrimesBigInteger c = (m_list[C] as PolynomFactor).Value;

            return((input.Pow(2).Multiply(a).Add(b.Multiply(input))).Add(c));
        }
Example #3
0
        public void RemoveMulipleOf(PrimesBigInteger value)
        {
            for (PrimesBigInteger i = value * 2; i <= m_Limit; i = i + value)
            {
                m_Sieved[i.LongValue] = -1;
            }

            m_RemovedMods.Add(value);

            if (value.Pow(2) <= GetMaxVisibleValue())
            {
                RedrawButtons();
            }
        }
        public void ValidateCalcInput(ref PrimesBigInteger from, ref PrimesBigInteger to)
        {
            try
            {
                PrimesBigInteger fromFactor = ValidateInput(m_tbFromCalcFactor);
                PrimesBigInteger fromBase   = ValidateInput(m_tbFromCalcBase);
                PrimesBigInteger fromExp    = ValidateInput(m_tbFromCalcExp);
                PrimesBigInteger fromSum    = ValidateInput(m_tbFromCalcSum);
                PrimesBigInteger toFactor   = ValidateInput(m_tbToCalcFactor);
                PrimesBigInteger toBase     = ValidateInput(m_tbToCalcBase);
                PrimesBigInteger toExp      = ValidateInput(m_tbToCalcExp);
                PrimesBigInteger toSum      = ValidateInput(m_tbToCalcSum);

                from = fromBase.Pow(fromExp.IntValue).Multiply(fromFactor).Add(fromSum);
                to   = toBase.Pow(toExp.IntValue).Multiply(toFactor).Add(toSum);

                if (m_IntervalSizeCanBeZero)
                {
                    if (!(from <= to))
                    {
                        from = null;
                        to   = null;
                        InfoCalc(Primes.Resources.lang.Validation.Validation.IllegalRangeValidator2, new TextBox[] { m_tbToCalcFactor, m_tbToCalcBase, m_tbToCalcExp, m_tbToCalcSum, m_tbFromCalcFactor, m_tbFromCalcBase, m_tbFromCalcExp, m_tbFromCalcSum }, OnlineHelp.OnlineHelpActions.None);
                    }
                }
                else
                {
                    if (!(from < to))
                    {
                        from = null;
                        to   = null;
                        InfoCalc(Primes.Resources.lang.Validation.Validation.IllegalRangeValidator, new TextBox[] { m_tbToCalcFactor, m_tbToCalcBase, m_tbToCalcExp, m_tbToCalcSum, m_tbFromCalcFactor, m_tbFromCalcBase, m_tbFromCalcExp, m_tbFromCalcSum }, OnlineHelp.OnlineHelpActions.None);
                    }
                }
            }
            catch (ControlValidationException cvex)
            {
                switch (cvex.ValidationResult)
                {
                case Primes.WpfControls.Validation.ValidationResult.ERROR:
                    ErrorCalc(cvex.Message, cvex.Control as TextBox, cvex.HelpAction);
                    break;

                case Primes.WpfControls.Validation.ValidationResult.WARNING:
                    InfoCalc(cvex.Message, cvex.Control as TextBox, cvex.HelpAction);
                    break;
                }
            }
        }
Example #5
0
 public StepResult DoStep(PrimesBigInteger value)
 {
     if (m_Expected.CompareTo(value) == 0)
     {
         m_Numbergrid.RemoveMulipleOf(value);
         m_Expected = m_Expected.NextProbablePrime();
         m_Current  = value;
         if (m_Current.Pow(2).CompareTo(m_MaxValue) >= 0)
         {
             return(StepResult.END);
         }
         return(StepResult.SUCCESS);
     }
     else
     {
         return(StepResult.FAILED);
     }
 }
Example #6
0
        public void ValidateCalcInput(ref PrimesBigInteger value)
        {
            try
            {
                PrimesBigInteger factor = ValidateInput(m_tbCalcFactor);
                PrimesBigInteger base_  = ValidateInput(m_tbCalcBase);
                PrimesBigInteger exp    = ValidateInput(m_tbCalcExp);
                PrimesBigInteger sum    = ValidateInput(m_tbCalcSum);
                value = base_.Pow(exp.IntValue).Multiply(factor).Add(sum);
            }
            catch (ControlValidationException cvex)
            {
                switch (cvex.ValidationResult)
                {
                case Primes.WpfControls.Validation.ValidationResult.ERROR:
                    ErrorCalc(cvex.Message, cvex.Control as TextBox, cvex.HelpAction);
                    break;

                case Primes.WpfControls.Validation.ValidationResult.WARNING:
                    InfoCalc(cvex.Message, cvex.Control as TextBox, cvex.HelpAction);
                    break;
                }
            }
        }
Example #7
0
        public void RemoveMulipleOf(PrimesBigInteger value)
        {
            DateTime start = DateTime.Now;

            PrimesBigInteger i = value.Multiply(PrimesBigInteger.Two);

            while (i.CompareTo(m_Limit) <= 0)
            {
                m_Sieved[i.LongValue] = false;
                i = i.Add(value);
            }
            //PrimesBigInteger counter = PrimesBigInteger.Two;
            //while (counter.Multiply(value).CompareTo(m_Limit)<=0)
            //{
            //  m_RemovedNumbers.Add(counter.Multiply(value));
            //  counter = counter.Add(PrimesBigInteger.One);
            //}
            m_RemovedMods.Add(value);
            if (value.Pow(2).CompareTo(GetMaxVisibleValue()) <= 0)
            {
                RedrawButtons();
            }
            TimeSpan diff = DateTime.Now - start;
        }
Example #8
0
 public override PrimesBigInteger Execute(PrimesBigInteger input)
 {
     return((input.Pow(2).Subtract(input)).Add(PrimesBigInteger.ValueOf(41)));
 }