// IComparable public int CompareTo(Double42 other) { Binary64 a = new Binary64(_value); Binary64 b = new Binary64(other._value); if (a.IsNan || b.IsNan) { throw new ArithmeticException("CompareTo cannot accept Nans."); } // Round away the insignificant bits of both. a = a.Round(INSIGNIFICANT_BITS); b = b.Round(INSIGNIFICANT_BITS); if (a.Bits < b.Bits) { return(-1); } else if (a.Bits > b.Bits) { return(1); } else { return(0); } }
public override int GetHashCode() { Binary64 a = new Binary64(_value); // Round away the insignificant bits. a = a.Round(INSIGNIFICANT_BITS); return(a.GetHashCode()); }
// IEquatable public bool Equals(Double42 other) { Binary64 a = new Binary64(_value); Binary64 b = new Binary64(other._value); if (a.IsNan || b.IsNan) { return(false); } // Round away the insignificant bits of both. a = a.Round(INSIGNIFICANT_BITS); b = b.Round(INSIGNIFICANT_BITS); return(a.Bits == b.Bits); }