예제 #1
0
        public void CountTrailingZerosTest2(UInt64 a, UInt64 b)
        {
            ReadOnlySpan <UInt64> s = stackalloc UInt64[] { a, b };

            Assert.IsTrue(BinaryNumerals.CountTrailingZeros(s) >= BinaryNumerals.CountTrailingZeros(s[1..]));
예제 #2
0
        public void CountTrailingZerosTest2(UInt64 a)
        {
            ReadOnlySpan <UInt64> s = stackalloc UInt64[] { a };

            Assert.IsTrue(BinaryNumerals.CountTrailingZeros(s) == BinaryNumerals.CountTrailingZeros(a));
        }
예제 #3
0
 public void CountTrailingZerosTest1(ReadOnlySpan <UInt64> aa)
 {
     Assert.IsTrue(BinaryNumerals.CountTrailingZeros(aa) >= 0);
     Assert.IsTrue(BinaryNumerals.CountTrailingZeros(aa) <= 64 * aa.Length);
 }
예제 #4
0
        public void CountTrailingZerosTest2()
        {
            ReadOnlySpan <UInt64> s = default;

            Assert.IsTrue(BinaryNumerals.CountTrailingZeros(s) == 0);
        }
        // 109 Cyc (special inpot set test6)
        public static ULong Remainder(ULong lowDividend, ULong highDividend, ULong lowDivisor, ULong highDivisor, out ULong highResult)
        {
            unchecked {
                if (0u != highDivisor)
                {
                    if (0 <= (Long)highDivisor)
                    {
                        ULong lowProduct;
                        ULong highProduct;
                        ULong lowResult;
                        ULong t;
                        {
                            int cc;
#if (NET5_0 || NET6_0 || NET5_0_OR_GREATER)
                            cc = BinaryNumerals.CountLeadingZeros(highDivisor);
                            t  = highDivisor << cc;
#else
                            // CountLeadingZeros
                            // ? using CountLeadingZeros is better or not?
                            cc = 0;
                            t  = highDivisor;
                            for (; 0 <= (Long)t; t <<= 1)
                            {
                                ++cc;
                            }
#endif
                            lowResult = MathEx.BigDivInternal(
                                lowDividend >> (Misc.ULong.BitSize - cc) | (highDividend << cc),
                                highDividend >> (Misc.ULong.BitSize - cc),
                                (lowDivisor >> (Misc.ULong.BitSize - cc)) | t);
                        }
                        t            = lowResult * highDivisor;
                        lowProduct   = MathEx.BigMul(lowResult, lowDivisor, out highProduct);
                        highProduct += t;
                        if (t > highProduct || highProduct > highDividend)
                        {
                            goto L_0001;
                        }
                        if (highDividend > highProduct || lowProduct <= lowDividend)
                        {
                            goto L_0002;
                        }
L_0001:
                        --lowResult;
                        highProduct = ((lowDivisor > lowProduct) ? (highProduct - highDivisor - 1u) : (highProduct - highDivisor));
                        lowProduct -= lowDivisor;
L_0002:
                        highResult = ((lowProduct > lowDividend) ? (highDividend - highProduct - 1u) : (highDividend - highProduct));
                        return(lowDividend - lowProduct);
                    }
                    else
                    {
                        highResult = 0u;
                        if (highDivisor <= highDividend && (highDivisor != highDividend || lowDivisor <= lowDividend))
                        {
                            return(MathEx.SubtractUnchecked(lowDividend, highDividend, lowDivisor, highDivisor, out highResult));
                        }
                        else
                        {
                            highResult = highDividend;
                            return(lowDividend);
                        }
                    }
                }
                else
                {
                    highResult = 0u;
                    return(MathEx.BigRemInternal(lowDividend, highDividend % lowDivisor, lowDivisor));
                }
            }
        }