Exemplo n.º 1
0
        public static double TruncateToPowerOfTwo(double d)
        {
            DoubleBits db = new DoubleBits(d);

            db.ZeroLowerBits(52);
            return(db.GetDouble());
        }
Exemplo n.º 2
0
        private void ComputeKey(int level, Envelope itemEnv)
        {
            double quadSize = DoubleBits.PowerOf2(level);

            //double quadSize = pow2.power(level);
            _pt.X = Math.Floor(itemEnv.MinX / quadSize) * quadSize;
            _pt.Y = Math.Floor(itemEnv.MinY / quadSize) * quadSize;
            _env.Initialize(_pt.X, _pt.X + quadSize, _pt.Y, _pt.Y + quadSize);
        }
Exemplo n.º 3
0
        public static int ComputeQuadLevel(Envelope env)
        {
            double dx    = env.Width;
            double dy    = env.Height;
            double dMax  = dx > dy ? dx : dy;
            int    level = DoubleBits.Exponent(dMax) + 1;

            return(level);
        }
Exemplo n.º 4
0
 /// <summary>
 /// This computes the number of common most-significan bits in the mantissa.
 /// It does not count the hidden bit, which is alway 1.  It does not determine whether the
 /// numbers have the same exponent - if they do not, the value computed by this function
 /// is meaningless.
 /// </summary>
 /// <param name="db"></param>
 /// <returns>Returns the number of common most-significant mantissa bits.</returns>
 public int NumCommonMantissaBits(DoubleBits db)
 {
     for (int i = 0; i < 52; i++)
     {
         int bitIndex = i + 12;
         if (GetBit(i) != db.GetBit(i))
         {
             return(i);
         }
     }
     return(52);
 }
Exemplo n.º 5
0
        /// <summary>
        /// Computes the exponent for the largest power of two
        /// less than the absolute value of the argument.
        /// In other words, finds the value n such that
        /// 2&#136;n &lt;= abs(num) &lt; 2&#136;(n+1)
        /// </summary>
        /// <param name="num"></param>
        /// <returns>The exponent.</returns>
        public static int Exponent(double num)
        {
            num = Math.Abs(num);
            double log  = Math.Log(num);
            double log2 = log / LOG_2;
            int    exp  = (int)Math.Floor(log2);

            int exp2 = DoubleBits.Exponent(num);

            if (exp != exp2)
            {
                //System.out.println(DoubleBits.toBinaryString(num));
                //System.out.println(num + " pow2 mismatch: " + exp + "   DoubleBits: " + exp2);
                double pow2exp  = DoubleBits.PowerOf2(exp);
                double pow2exp2 = DoubleBits.PowerOf2(exp2);
                //System.out.println(pow2exp + "   pow2exp2 = " + pow2exp2);
            }
            return(exp);
        }
Exemplo n.º 6
0
        public static double MaximumCommonMantissa(double d1, double d2)
        {
            if (d1 == 0.0 || d2 == 0.0)
            {
                return(0.0);
            }

            DoubleBits db1 = new DoubleBits(d1);
            DoubleBits db2 = new DoubleBits(d2);

            if (db1.GetExponent() != db2.GetExponent())
            {
                return(0.0);
            }

            int maxCommon = db1.NumCommonMantissaBits(db2);

            db1.ZeroLowerBits(64 - (12 + maxCommon));
            return(db1.GetDouble());
        }
Exemplo n.º 7
0
        public static String ToBinaryString(double d)
        {
            DoubleBits db = new DoubleBits(d);

            return(db.ToString());
        }
Exemplo n.º 8
0
        public static int Exponent(double d)
        {
            DoubleBits db = new DoubleBits(d);

            return(db.GetExponent());
        }
Exemplo n.º 9
0
		public static double MaximumCommonMantissa(double d1, double d2)
		{
			if (d1 == 0.0 || d2 == 0.0) return 0.0;

			DoubleBits db1 = new DoubleBits(d1);
			DoubleBits db2 = new DoubleBits(d2);

			if (db1.GetExponent() != db2.GetExponent()) return 0.0;

			int maxCommon = db1.NumCommonMantissaBits(db2);
			db1.ZeroLowerBits(64 - (12 + maxCommon));
			return db1.GetDouble();
		}
Exemplo n.º 10
0
		public static String ToBinaryString(double d)
		{
			DoubleBits db = new DoubleBits(d);
			return db.ToString();
		}
Exemplo n.º 11
0
		public static double TruncateToPowerOfTwo(double d)
		{
			DoubleBits db = new DoubleBits(d);
			db.ZeroLowerBits(52);
			return db.GetDouble();
		}
Exemplo n.º 12
0
		public static int Exponent(double d)
		{
			DoubleBits db = new DoubleBits(d);
			return db.GetExponent();
		}
Exemplo n.º 13
0
		/// <summary>
		/// This computes the number of common most-significan bits in the mantissa.
		/// It does not count the hidden bit, which is alway 1.  It does not determine whether the
		/// numbers have the same exponent - if they do not, the value computed by this function
		/// is meaningless.
		/// </summary>
		/// <param name="db"></param>
		/// <returns>Returns the number of common most-significant mantissa bits.</returns>
		public int NumCommonMantissaBits( DoubleBits db )
		{
			for (int i = 0; i < 52; i++)
			{
				int bitIndex = i + 12;
				if ( GetBit(i) != db.GetBit(i) )
					return i;
			}
			return 52;
		}