Exemplo n.º 1
0
        public TFrac(string fraction)
        {
            Regex FracRegex   = new Regex(@"^-?(\d+)/(\d+)$");
            Regex NumberRegex = new Regex(@"^-?\d+/?$");

            if (FracRegex.IsMatch(fraction))
            {
                List <string> FracParts = fraction.Split('/').ToList();
                Numerator   = new TNumber(FracParts[0]);
                Denominator = new TNumber(FracParts[1]);
                if (Denominator.IsZero())
                {
                    Numerator   = new TNumber(0);
                    Denominator = new TNumber(1);
                    return;
                }
                long gcdResult = GCD((long)Numerator.Number, (long)Denominator.Number);
                if (gcdResult > 1)
                {
                    Numerator   /= gcdResult;
                    Denominator /= gcdResult;
                }
                return;
            }
            else if (NumberRegex.IsMatch(fraction))
            {
                Numerator   = new TNumber(fraction);
                Denominator = new TNumber(1);
                return;
            }
            else
            {
                Numerator   = new TNumber(0);
                Denominator = new TNumber(1);
                return;
            }
        }
Exemplo n.º 2
0
 public override bool IsZero()
 {
     return(Real.IsZero() && Imaginary.IsZero());
 }
Exemplo n.º 3
0
 public override bool IsZero()
 {
     return(Numerator.IsZero());
 }
Exemplo n.º 4
0
 public override bool IsZero()
 {
     return(Number.IsZero());
 }