/// <summary>
        /// 指定された値を指数として Rational 値を累乗します。
        /// </summary>
        /// <param name="ebase">累乗対象の Rational。</param>
        /// <param name="exponent">累乗の指数を指定する Rational。</param>
        private static Rational Pow(Rational ebase, BigUInteger exponent)
        {
            if (exponent.IsZero)
            {
                return(Rational.One);
            }
            else if (exponent.IsOne)
            {
                return(ebase);
            }

            var resultBase = Rational.One;

            while (exponent > BigUInteger.One)
            {
                if (!exponent.IsEven)
                {
                    resultBase *= ebase;
                }
                ebase   *= ebase;
                exponent = BigUInteger.RightShift(exponent, 0, 1);
            }

            return(resultBase * ebase);
        }
        private static Rational UnderflowTrimer(Rational value, Rational targetOder)
        {
            var nowOder = GetOrder(value.Denominator) - targetOder;

            if (nowOder > 0)
            {
                var(arrayShift, innerShift) = Math.DivRem(nowOder, BigUInteger.ContainerItemSizeWithBit);
                value.Numerator             = BigUInteger.RightShift(value.Numerator, (int)arrayShift, (int)innerShift);
                value.Denominator           = BigUInteger.RightShift(value.Denominator, (int)arrayShift, (int)innerShift);
            }
            return(value);
        }
        /// <summary>
        /// 指定の数値を指定した値で累乗した値を返します。
        /// </summary>
        /// <param name="ebase">累乗対象の BigUInteger。</param>
        /// <param name="exponent">累乗を指定する BigUInteger。</param>
        /// <returns>数値 ebase を exponent で累乗した値。</returns>
        public static BigUInteger Pow(BigUInteger ebase, BigUInteger exponent)
        {
#if DEBUG && !DLLDEBUG
            return(System.Math.Pow(ebase.Value, exponent.Value));
#else
            if (ebase.IsOne || exponent.IsOne)
            {
                //x=1; 1
                return(ebase);
            }

            if (exponent == 0)
            {
                return(BigUInteger.One);
            }

            if (ebase.IsZero)
            {
                //x=0; y>0.   0
                return(BigUInteger.Zero);
            }

            if (exponent.IsZero)
            {
                return(BigUInteger.One);
            }

            if (exponent.IsZero)
            {
                return(BigUInteger.One);
            }
            else if (exponent.IsOne)
            {
                return(ebase);
            }

            var resultBase = BigUInteger.One;
            while (exponent > BigUInteger.One)
            {
                if (!exponent.IsEven)
                {
                    resultBase *= ebase;
                }
                ebase   *= ebase;
                exponent = BigUInteger.RightShift(exponent, 0, 1);
            }

            return(resultBase * ebase);
#endif
        }
Exemple #4
0
 public void Plus()
 {
     ExecTest(BigUInteger.RightShift(new BigUInteger(new byte[] { 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0 }), 32), new byte[] { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0 });
 }