/// <summary>
        /// Phân số tối giản.
        /// </summary>
        public void Minimalism()
        {
            BigDecimal n = Minimalism(this.Numerator, this.Denominator);

            Numerator   = Numerator.Divide(n.Abs());
            Denominator = Denominator.SetScale(5, RoundingMode.HalfEven);
            Denominator = Denominator.Divide(n.Abs());
        }
Example #2
0
 public BigInteger Ceiling()
 {
     if (Denominator.CompareTo(BigInteger.One) == 0)
     {
         return(Numerator);
     }
     if (Numerator.CompareTo(BigInteger.Zero) > 0)
     {
         return(Numerator.Divide(Denominator).Add(BigInteger.One));
     }
     return(Numerator.Divide(Denominator));
 }
Example #3
0
 public BigInteger Floor()
 {
     /* is already integer: return the numerator
      */
     if (Denominator.CompareTo(BigInteger.One) == 0)
     {
         return(Numerator);
     }
     if (Numerator.CompareTo(BigInteger.Zero) > 0)
     {
         return(Numerator.Divide(Denominator));
     }
     return(Numerator.Divide(Denominator).Subtract(BigInteger.One));
 }
Example #4
0
        private void Normalize()
        {
            // compute greatest common divisor of numerator and denominator
            BigInteger g = Numerator.Gcd(Denominator);

            if (g.CompareTo(BigInteger.One) > 0)
            {
                Numerator   = Numerator.Divide(g);
                Denominator = Denominator.Divide(g);
            }
            if (Denominator.CompareTo(BigInteger.Zero) == -1)
            {
                Numerator   = Numerator.Negate();
                Denominator = Denominator.Negate();
            }
        }
Example #5
0
 public BigInteger Truncate()
 {
     return(Denominator.CompareTo(BigInteger.One) == 0 ? Numerator : Numerator.Divide(Denominator));
 }