Example #1
0
        /// <summary>
        /// Main method
        /// </summary>
        public void Execute()
        {
            BigInteger result = 0;

            //First checks if both inputs are set
            if (input1 != null && input2 != null)
            {
                ProgressChanged(0.5, 1.0);

                try
                {
                    //As the user changes the operation different outputs are calculated.
                    switch (settings.Operat)
                    {
                    // x + y
                    case 0:
                        result = Input1 + Input2;
                        break;

                    // x - y
                    case 1:
                        result = Input1 - Input2;
                        break;

                    //x * y
                    case 2:
                        result = Input1 * Input2;
                        break;

                    // x / y
                    case 3:
                        result = Input1 / Input2;
                        break;

                    // x ^ y
                    case 4:
                        if (Mod != 0)
                        {
                            if (Input2 >= 0)
                            {
                                result = BigInteger.ModPow(Input1, Input2, Mod);
                            }
                            else
                            {
                                result = BigInteger.ModPow(BigIntegerHelper.ModInverse(Input1, Mod), -Input2, Mod);
                            }
                        }
                        else
                        {
                            result = BigIntegerHelper.Pow(Input1, Input2);
                        }
                        break;

                    // gcd(x,y)
                    case 5:
                        result = Input1.GCD(Input2);
                        break;

                    // lcm(x,y)
                    case 6:
                        result = Input1.LCM(Input2);
                        break;

                    // sqrt(x,y)
                    case 7:
                        result = Input1.Sqrt();
                        break;

                    // modinv(x,y)
                    case 8:
                        if (Input2 != 0)
                        {
                            result = BigIntegerHelper.ModInverse(Input1, Input2);
                        }
                        else
                        {
                            result = 1 / Input1;
                        }
                        break;

                    // phi(x)
                    case 9:
                        result = Input1.Phi();
                        break;
                    }

                    Output = (Mod == 0) ? result : (((result % Mod) + Mod) % Mod);
                }
                catch (Exception e)
                {
                    GuiLogMessage("Big Number fail: " + e.Message, NotificationLevel.Error);
                    return;
                }

                ProgressChanged(1.0, 1.0);
            }
        }