Example #1
0
 public static bool operator ==(Number a, Number b)
 {
     if (a is null && b is null)
     {
         return(true);
     }
     if (a is null || b is null)
     {
         return(false);
     }
     (a, b, _) = Functional.MakeEqual(a, b);
     if (a.IsReal() && b.IsReal())
     {
         var aAsReal = (a as RealNumber);
         var bAsReal = (b as RealNumber);
         if (!aAsReal.IsDefinite() && !bAsReal.IsDefinite())
         {
             return(aAsReal.State == bAsReal.State);
         }
         else if (!aAsReal.IsDefinite() || !bAsReal.IsDefinite())
         {
             return(false);
         }
         // else both are defined
     }
     if (a.Type != b.Type)
     {
         return(false);
     }
     return(SuperSwitch(
                num => IntegerNumber.AreEqual(num[0], num[1]),
                num => RationalNumber.AreEqual(num[0], num[1]),
                num => RealNumber.AreEqual(num[0], num[1]),
                num => ComplexNumber.AreEqual(num[0], num[1]),
                a.Type,
                a, b
                ));
 }
 internal static bool AreEqual(RationalNumber a, RationalNumber b)
 => a.Numerator == b.Numerator && a.Denominator == b.Denominator && a.State == b.State;