コード例 #1
0
ファイル: BigFloat.cs プロジェクト: Gabbe-x/smartx-dotnet
        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
ファイル: BigFloat.cs プロジェクト: Gabbe-x/smartx-dotnet
        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));
        }
コード例 #5
0
        /// <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
ファイル: BigFloat.cs プロジェクト: Gabbe-x/smartx-dotnet
 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);
 }