예제 #1
0
        public int CompareTo(BigFloat that)
        {
            Contract.Requires(exponentSize == that.exponentSize);
            Contract.Requires(significandSize == that.significandSize);

            if (value == "" && that.value == "")
            {
                int cmpThis = IsZero ? 0 : isSignBitSet ? -1 : 1;
                int cmpThat = that.IsZero ? 0 : that.isSignBitSet ? -1 : 1;

                if (cmpThis == cmpThat)
                {
                    if (exponent == that.exponent)
                    {
                        return(cmpThis * significand.CompareTo(that.significand));
                    }

                    return(cmpThis * exponent.CompareTo(that.exponent));
                }

                if (cmpThis == 0)
                {
                    return(-cmpThat);
                }

                return(cmpThis);
            }

            if (value == that.value)
            {
                return(0);
            }

            if (value == "NaN" || that.value == "+oo" || value == "-oo" && that.value != "NaN")
            {
                return(-1);
            }

            return(1);
        }