Example #1
0
        public static double TruncateToPowerOfTwo(double d)
        {
            DoubleBits db = new DoubleBits(d);

            db.ZeroLowerBits(52);

            return(db.GetDouble());
        }
Example #2
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());
        }