Ejemplo n.º 1
0
 private void Normalize()
 {
     if (this.Numerator == 0)
     {
         this.Denominator = 1;
     }
     else
     {
         var g = NormalizedRational.GCD(this.Numerator, this.Denominator);
         this.Numerator   = this.Numerator / g;
         this.Denominator = this.Denominator / g;
     }
 }
Ejemplo n.º 2
0
        private static int GCD(int x, int y)
        {
            // find greatest common divisor of x and y
            int ans;
            int z;

            if (x < y)
            {
                ans = NormalizedRational.GCD(y, x);
            }
            else if (x % y == 0)
            {
                ans = y;
            }
            else
            {
                z   = x % y;
                ans = NormalizedRational.GCD(y, z);
            }
            return(ans);
        }
Ejemplo n.º 3
0
 private void NormalizedInvariant()
 {
     Contract.Invariant(NormalizedRational.GCD(this.Numerator, this.Denominator) == 1);
 }