Kaung Htet Kyaw

Kaung Htet Kyaw

  • NA
  • 61
  • 5.9k

How to fix mathstuff does not exist error

Jan 11 2020 2:39 AM
Hi, there. I am trying to calculate the focal length of the mirror and there is an error that mathstuff function does not exist in the current context. I want to know whether "Math Stuff" is a function or not and if it is not, please tell me which function should I replace in it. I indicated my error in the code by pointing with an arrow and text in the bracket.I will be pleased if someone solves my problem.
 
Here is my code....
 
 
 
 
 namespace Physics_Calculator_Program
{
    public partial class frmFocalLengthofMirrorCalculation : Form
    {
        public frmFocalLengthofMirrorCalculation()
        {
            InitializeComponent();
        }
        private void btnCalculate_Click(object sender, EventArgs e)
        {
            try
            {
                decimal u, v, f;
                u = Convert.ToDecimal(txtu.Text);
                v = Convert.ToDecimal(txtv.Text);
                f = (1 / u) + (1 / v);
                lblF.Text = Convert.ToDecimal(f) + " cm";
            }
            catch (Exception)
            {
                MessageBox.Show("Please Enter Numbers only", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }     
            class Fraction
        {
            public long numerator, denominator;
            public Fraction(string txt)
            {
                string[] pieces = txt.Split('/');
                numerator = long.Parse(pieces[0]));
                denominator = long.Parse(pieces[1]);
                Simplify();
            }
            public Fraction(long numer, long denom)
            {
                numerator = numer;
                denominator = denom;
                Simplify();
            }
            public static Fraction operator +(Fraction u, Fraction v)
            {
                long gcd_uv = MathStuff.GCD(u.denominator, v.denominator); <------( This is the error I am causing)...
                long numer = u.numerator * (v.numerator / gcd_uv) + v.numerator * (u.numerator / gcd_uv);
                long denom = u.denominator * (v.denominator / gcd_uv);
                return new Fraction(numer, denom);
            }
            private void Simplify()
            {
                // Simplify the sign.
                if (denominator < 0)
                {
                    numerator = -numerator;
                    denominator = -denominator;
                }
                // Factor out the greatest common divisor of the
                // numerator and the denominator.
                long gcd_ab = GCD(numerator, denominator);
                numerator = numerator / gcd_ab;
                denominator = denominator / gcd_ab;
            }
            // Convert a to a double.
            public static implicit operator double (Fraction a)
            {
                return (double)a.numerator / a.denominator;
            }
            // Return the fraction's value as a string.
            public override string ToString()
            {
                return numerator.ToString() + "/" + denominator.ToString();
            }
            private long GCD(long u, long v)
            {
                u = Math.Abs(u);
                v = Math.Abs(v);
                // Pull out remainders.
                for (;;)
                {
                    long remainder = u % v;
                    if (remainder == 0) return v;
                    u = v;
                    v = remainder;
                };
            }
        }
        private void btnClose_Click(object sender, EventArgs e)
        {
            Close();
        }
    }
    }

Answers (2)