Ejemplo n.º 1
0
        internal static NumberDiyFp Normalize(NumberDiyFp a)
        {
            NumberDiyFp result = new NumberDiyFp(a.fv, a.ev);

            result.Normalize();
            return(result);
        }
Ejemplo n.º 2
0
        // Returns the two boundaries of first argument.
        // The bigger boundary (m_plus) is normalized. The lower boundary has the same
        // exponent as m_plus.
        public static void NormalizedBoundaries(long d64, NumberDiyFp m_minus, NumberDiyFp m_plus)
        {
            NumberDiyFp v = AsDiyFp(d64);
            bool        significand_is_zero = (v.F() == kHiddenBit);

            m_plus.SetF((v.F() << 1) + 1);
            m_plus.SetE(v.E() - 1);
            m_plus.Normalize();
            if (significand_is_zero && v.E() != kDenormalExponent)
            {
                // The boundary is closer. Think of v = 1000e10 and v- = 9999e9.
                // Then the boundary (== (v - v-)/2) is not just at a distance of 1e9 but
                // at a distance of 1e8.
                // The only exception is for the smallest normal: the largest denormal is
                // at the same distance as its successor.
                // Note: denormals have the same exponent as the smallest normals.
                m_minus.SetF((v.F() << 2) - 1);
                m_minus.SetE(v.E() - 2);
            }
            else
            {
                m_minus.SetF((v.F() << 1) - 1);
                m_minus.SetE(v.E() - 1);
            }
            m_minus.SetF(m_minus.F() << (m_minus.E() - m_plus.E()));
            m_minus.SetE(m_plus.E());
        }