/// <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()); }
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)); }
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)); }
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(); } }
public BigInteger Truncate() { return(Denominator.CompareTo(BigInteger.One) == 0 ? Numerator : Numerator.Divide(Denominator)); }