Redzen.Structures.Compact.FixedPointDecimal.Compare C# (CSharp) Method

Compare() public static method

Compares two specified FixedPointDecimal values.
public static Compare ( FixedPointDecimal d1, FixedPointDecimal d2 ) : int
d1 FixedPointDecimal The first to compare.
d2 FixedPointDecimal The second to compare.
return int
        public static int Compare(FixedPointDecimal d1, FixedPointDecimal d2)
        {
            // Test for null values.
            if((d1._data & 0x80000000) == 0 && (d2._data & 0x80000000) == 0)
            {   // Both values are null;
                return 0;
            }

            if((d1._data & 0x80000000) == 0)
            {   // d1 is null.
                return -1;
            }

            if((d2._data & 0x80000000) == 0)
            {   // d2 is null.
                return 1;
            }

            // Both values are non null. Extract significands to signed int (and apply sign bit).
            int s1 = (int)(d1._data & 0x3FFFFFFFu | ((d1._data & 0x40000000) << 1));
            int s2 = (int)(d2._data & 0x3FFFFFFFu | ((d2._data & 0x40000000) << 1));

            // Compare signed significands.
            if(s1 > s2)
            {
                return 1;
            }
            else if(s1 < s2)
            {
                return -1;
            }
            return 0;
        }