コード例 #1
0
ファイル: IntMathTest.cs プロジェクト: zhabis/nfx
        public void IntMathLog()
        {
            Aver.AreEqual(10, IntMath.Log(1024, 2));
            Aver.AreEqual(2, IntMath.Log(9, 3));
            Aver.AreEqual(2, IntMath.Log(11, 3));
            Aver.AreEqual(1, IntMath.Log(2, 2));
            Aver.AreEqual(0, IntMath.Log(1, 2));
            Aver.Throws <NFXException>(() => IntMath.Log(0, 2));

            Aver.AreEqual(62, IntMath.Log(1L << 62, 2));
            Aver.AreEqual(32, IntMath.Log(1L << 32, 2));
            Aver.AreEqual(10, IntMath.Log(1024, 2));
            Aver.AreEqual(4, IntMath.Log(16, 2));
            Aver.AreEqual(3, IntMath.Log(8, 2));
            Aver.AreEqual(1, IntMath.Log(2, 2));
            Aver.AreEqual(0, IntMath.Log(1, 2));
        }
コード例 #2
0
        public void IntMathLog()
        {
            Assert.AreEqual(10, IntMath.Log(1024, 2));
            Assert.AreEqual(2, IntMath.Log(9, 3));
            Assert.AreEqual(2, IntMath.Log(11, 3));
            Assert.AreEqual(1, IntMath.Log(2, 2));
            Assert.AreEqual(0, IntMath.Log(1, 2));
            Assert.Throws <NFXException>(delegate { IntMath.Log(0, 2); });

            Assert.AreEqual(62, IntMath.Log(1L << 62, 2));
            Assert.AreEqual(32, IntMath.Log(1L << 32, 2));
            Assert.AreEqual(10, IntMath.Log(1024, 2));
            Assert.AreEqual(4, IntMath.Log(16, 2));
            Assert.AreEqual(3, IntMath.Log(8, 2));
            Assert.AreEqual(1, IntMath.Log(2, 2));
            Assert.AreEqual(0, IntMath.Log(1, 2));
        }
コード例 #3
0
        /// <summary>
        /// Reset the internal state of the throttling strategy
        /// </summary>
        public override void Reset()
        {
            int maxSeconds = (int)IntMath.UpperPow(m_BucketsPerSec * m_Interval, 2);

            m_LogBucketsSec   = IntMath.Log(m_BucketsPerSec, 2);
            m_BucketCount     = maxSeconds * m_BucketsPerSec;
            m_BucketMask      = m_BucketCount - 1;
            m_BucketsInterval = m_Interval << m_LogBucketsSec;

            // must be power of two
            Debug.Assert((m_BucketCount & (m_BucketCount - 1)) == 0);

            m_Buckets = new double[m_BucketCount];

            Array.Clear(m_Buckets, 0, m_Buckets.Length);
            m_LastTimeBucket = 0;
            m_Sum            = 0;
        }