示例#1
0
        public static BigFloat Truncate(BigFloat value)
        {
            var numerator = value.Numerator;

            numerator -= BigInteger.Remainder(numerator, value.Denominator);

            return(Factor(new BigFloat(numerator, value.Denominator)));
        }
示例#2
0
        public BigFloat Floor()
        {
            if (numerator < 0)
            {
                numerator += denominator - BigInteger.Remainder(numerator, denominator);
            }
            else
            {
                numerator -= BigInteger.Remainder(numerator, denominator);
            }

            Factor();
            return(this);
        }
示例#3
0
        public static BigFloat Floor(BigFloat value)
        {
            var numerator = value.Numerator;

            if (numerator < 0)
            {
                numerator += value.Denominator - BigInteger.Remainder(numerator, value.Denominator);
            }
            else
            {
                numerator -= BigInteger.Remainder(numerator, value.Denominator);
            }

            return(Factor(new BigFloat(numerator, value.Denominator)));
        }
示例#4
0
        object IConvertible.ToType(Type conversionType, IFormatProvider provider)
        {
            var scaleDivisor = BigInteger.Pow(new BigInteger(10), this._scale);
            var remainder    = BigInteger.Remainder(this._unscaledValue, scaleDivisor);
            var scaledValue  = BigInteger.Divide(this._unscaledValue, scaleDivisor);

            if (scaledValue > new BigInteger(Decimal.MaxValue))
            {
                throw new ArgumentOutOfRangeException("value", "The value " + this._unscaledValue + " cannot fit into " + conversionType.Name + ".");
            }

            var leftOfDecimal  = (decimal)scaledValue;
            var rightOfDecimal = ((decimal)remainder) / ((decimal)scaleDivisor);

            var value = leftOfDecimal + rightOfDecimal;

            return(Convert.ChangeType(value, conversionType));
        }
        /// <summary>
        /// Find the great common divisor for a and b
        /// </summary>
        public static BigInteger FindGCD(BigInteger a, BigInteger b, out BigInteger x, out BigInteger y)
        {
            // Base Case
            if (a == 0)
            {
                x = BigInteger.Zero;
                y = BigInteger.One;

                return(b);
            }

            // To store results of recursive call
            var gcd = FindGCD(BigInteger.Remainder(b, a), a, out BigInteger x1, out BigInteger y1);

            // Update x and y using results of recursive
            // call
            x = BigInteger.Subtract(y1, BigInteger.Multiply(BigInteger.Divide(b, a), x1));
            y = new BigInteger(x1.ToByteArray());

            return(gcd);
        }
示例#6
0
 public static BigFloat Decimals(BigFloat value)
 => new BigFloat(BigInteger.Remainder(value.Numerator, value.Denominator), value.Denominator);
示例#7
0
 public BigRational GetFractionPart()
 {
     return new BigRational(BigInteger.Remainder(m_numerator, m_denominator), m_denominator);
 }
示例#8
0
        public BigFloat Decimals()
        {
            BigInteger result = BigInteger.Remainder(numerator, denominator);

            return(new BigFloat(result, denominator));
        }
示例#9
0
 public BigFloat Truncate()
 {
     numerator -= BigInteger.Remainder(numerator, denominator);
     Factor();
     return(this);
 }